#1 2020-06-07 15:47:41

TheDoc
Member
Munich / Germany
2015-10-18
173

Image rotation - once again

Hi,

semes like since some recent point in the past I also have the problem of portrait images not rotated properly. See e.g. https://www.feuster.com/piwigo/picture? … _21052020.

It seems that this occurs only with smartphone (both Galaxy and Pixel) images but not with Canon 70D. This can be seen in the screen shot: incorrect image is from smartphone, correct one (green highlight) is from Canon. The same seems to be true for all other galleries I have checked.

http://www.feuster.com/thomas/Clipboard01.jpg

Since I usually verify a new gallery after uploading I'm pretty certain this was shown correctly not long ago without any uploads / changes in between.

Does anyone have any idea where to dig deeper for the issue?

Thanks!
Thomas

    Piwigo 2.10.2 Check for upgrade
    Operating system: Linux
    PHP: 7.3.17 (Show info) [2020-06-07 15:43:22]
    MySQL: 5.5.60-0+deb7u1-log [2020-06-07 15:43:22]
    Graphics Library: External ImageMagick 6.8.9-9

Last edited by TheDoc (2020-06-07 15:52:13)

Offline

 

#2 2020-06-07 17:34:16

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7245

Re: Image rotation - once again


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#3 2020-06-07 22:55:46

TheDoc
Member
Munich / Germany
2015-10-18
173

Re: Image rotation - once again

Thanks for the link.

But since it worked before without the plugin I'd rather convert things to the previous state. ALSO if viewed with any other imaging software the pictures are shown correctly.

Offline

 

#4 2020-06-07 23:47:00

executive
Member
2017-08-16
1233

Re: Image rotation - once again

I think it has to with your source photos/software, not Piwigo. Different software packages apply rotation functions inconsistently, leading to this problem. I've seen it before on the Windows platform, where the viewing app ignored metadata rotation.

Piwigo uses image libraries that are used pretty much across the web.

My digital camera and mobile photos are displayed correctly.

You need to correct it with the extension, or revise your workflow.

Last edited by executive (2020-06-07 23:48:00)

Offline

 

#5 2020-06-11 02:57:44

hgregg
Member
2020-05-25
14

Re: Image rotation - once again

Hi,

I have a similar, but slightly different problem.

I'm new to piwigo, so don't know if this behavior has changed, as noted by TheDoc.

I ftp files to a gallery, and sync. Landscape photos work well, just as expected.

Portrait photos are another matter. If I manually rotate and save a photo (on my desktop, then ftp the photo to my site), it works well, and exactly as expected.

However, if I don't manually rotate the photo (its orientation is defined by the embedded EXIF data), this is what happens:
1) photo displays well and properly rotated on my desktop prior to ftp to my site
2) after ftp & sync, the database entry gives a width wider than the height - it seems to come into the system in landscape mode
3) in viewing my piwigo gallery, the thumbnails and photo come out squished and fat - the portrait photo forced into landscape mode (and obviously distorted)
4) Unusual, but the iOS app displays everything correctly - the iOS app must go directly to the photos (and associated EXIF data, ignoring the database dimensions) to figure out the proper orientation.

To me, it appears that the initial sync of the new photo to the database isn't taking EXIF data into account.

As a newbie, I may have something set incorrectly, but it doesn't seem so. I'm happy to try troubleshooting if someone gives me a pointer as to where to look.

Offline

 

#6 2020-06-11 07:30:58

executive
Member
2017-08-16
1233

Re: Image rotation - once again

what if you use the web upload?

Offline

 

#7 2020-06-11 19:18:22

hgregg
Member
2020-05-25
14

Re: Image rotation - once again

Dear executive,

Thank you for the suggestion - I tried uploading the same photo (not manually rotated, but requiring rotation as noted in the EXIF data), and the web upload worked perfectly.

So clearly, there is some difference in the code for web upload (and implied sync) and the manual sync (after ftp).

I'm interested in keeping physical albums, so would really like the manual sync to take EXIF data into account.

Any troubleshooting tips?

Thanks.

Offline

 

#8 2020-06-14 16:21:30

TheDoc
Member
Munich / Germany
2015-10-18
173

Re: Image rotation - once again

Hi,

I did some more digging for my case but didn't make much progress :-(

Question: In which php are the derivatives created?

My observations:

1) Initial image uploaded via ftp has height > width in exif
2) Same values are stored in database
3) all derivatives in _data/i/... also have height > width in exif
4) BUT all smartphone derivatives have "Rotate 90 CW" as orientation in exif
5) all camera derivatives are OK

I can't seem to find any meaningful difference in exif between smartphone and camera images. No idea based on what info piwigo decides that a rotation for the smartphone derivatives is required.

So I would need to have a look at the code that decides that. I tried looking at the value of $src_image->rotation in derivative.inc.php but there it was always 0 for any image I checked.

Any pointers appreciated!

Offline

 

#9 2020-06-15 02:03:11

hgregg
Member
2020-05-25
14

Re: Image rotation - once again

Hi all,

I've been pouring over the piwigo code, trying to make sense of this, and have come to the following conclusion (of course I may be wrong! Would not be the first time):

1) Uploading with the web interface, piwigo checks the exif data, and sets the database entry "rotation" correctly. Everything works as expected.

2) Using FTP to create physical albums, then using synchronize, piwigo does NOT check the exif "Orientation" of the photos. I would have thought it would have done this.

So I took it upon myself to try to fix it, and I think I have succeeded. I created a personal plug in that added a new exif tag, "rotation", that has the value needed for piwigo based on the "Orientation" exif data. And it is working on the few photos I've tried to this point.

Here is my local config:
<?php
/*
  Added the following to show more information per photograph

  Note that "rotation" normally doesn't exist; it is created and
  added onto the $exif array using a personal plugin
*/

$conf['use_exif'] = true;
$conf['show_exif'] = true;

$conf['show_exif_fields'] = array(
  'DateTimeOriginal',
  'Make',
  'Model',
  'FocalLengthIn35mmFilm',
  //'Orientation',           // remove comment if you wish to see exif orientation
  //'rotation',              // and resulting rotation
  'UserComment'
  );

$conf['use_exif_mapping'] = array(
  'date_creation'        => 'DateTimeOriginal',
  'comment'              => 'UserComment',
  'rotation'             => 'rotation',
  );

?>
===========================================

and here is the Personal Plugin I created:
<?php
/*
Plugin Name: Rotate
Version: 1.0
Description: Use EXIF data to set variable "rotation"
Plugin URI:
Author: hgregg
Author URI:

EXIF orientation ==> piwigo rotation   change
    1, 2                0 or NULL      no rotation
    3, 4                2              180 rotation
    5, 6                3              270 clockwise
    7, 8                1               90 clockwise

This is a bit of a hack, adding a non-exif tag to the array, but it seems to work.
*/

add_event_handler('format_exif_data', 'rotation_based_on_exif_data');

function rotation_based_on_exif_data($exif, $filepath) {

  if (array_key_exists('Orientation', $exif)) {
    switch($exif['Orientation']) {
      case 3:
      case 4:
        $exif['rotation'] = 2;
        break;
      case 5:
      case 6:
        $exif['rotation'] = 3;
        break;
      case 7:
      case 8:
        $exif['rotation'] = 1;
        break;
    }
   
  }
 
  return $exif;
}


?>
===========================================

This may not be very elegant code (I have very little [read as none before this project] php coding experience), but does update the "rotation" database entry upon sync.

TheDoc - would this work for you? I believe our issues are similar ...

Kind regards,
hgregg.

Offline

 

#10 2020-06-16 14:14:35

TheDoc
Member
Munich / Germany
2015-10-18
173

Re: Image rotation - once again

hgregg wrote:

TheDoc - would this work for you? I believe our issues are similar ...

I would need to have a look at that but thanks a lot for the code!

What suprises me is:

- I'm pretty sure it worked until recently. I would have noticed if my recent uploads (1-2 months ago) would have lead to such images
- Works with Canon but not with Samsung & Google? Seems to point to some difference in EXIF that I couldn't find so far

So I would be interested to figure out the root cause and fix that... It might point to some issue in my picture workflow prioir to uploading

Offline

 

#11 2020-06-18 23:29:25

hgregg
Member
2020-05-25
14

Re: Image rotation - once again

It turns out that sometimes a NULL is passed to this PersonalPlugin, and it gives unsightly errors. The below code is an update to correct this.

===================

<?php
/*
Plugin Name: Rotate
Version: 1.1
Description: Use EXIF data to set variable "rotation"
Plugin URI:
Author: hgregg
Author URI:

EXIF orientation ==> piwigo rotation   change
    1, 2                0 or NULL      no rotation
    3, 4                2              180 rotation
    5, 6                3              270 clockwise
    7, 8                1               90 clockwise

This is a bit of a hack, adding a non-exif tag to the array, but it seems to work.
*/

add_event_handler('format_exif_data', 'rotation_based_on_exif_data');

function rotation_based_on_exif_data($exif, $filepath) {
 
  if (!is_null($exif)) {
    if (array_key_exists('Orientation', $exif)) {
      switch($exif['Orientation']) {
        case 3:
        case 4:
          $exif['rotation'] = 2;
          break;
        case 5:
        case 6:
          $exif['rotation'] = 3;
          break;
        case 7:
        case 8:
          $exif['rotation'] = 1;
          break;
      }
    }
  }
  return $exif;
}


?>

Offline

 

#12 2020-07-05 19:16:01

TheDoc
Member
Munich / Germany
2015-10-18
173

Re: Image rotation - once again

This is getting stranger each time I try to dig into it... Some more debugging shows:

- All images have EXIF orientation set to "1" - which should not lead to rotation in piwigo
- For images shown incorrectly the database shows width x height e.g. '960 x 1280' which is correct for portrait

SO it seems that the EXIT data should be OK.

With log level DEBUG I can see the following commands for thumb creation:

Code:

[2020-07-05 18:49:27]  [DEBUG]  [i.php]  convert "MY_PATH_HERE/piwigo/galleries/Muenchen/tagestouren/Ismaning-Erding-Ebersberg_20200428/20200428_110728.jpg" -filter Lanczos -resize 445x594! -quality 97 -interlace line -sampling-factor 4:2:2 "MY_PATH_HERE/piwigo/_data/i/galleries/Muenchen/tagestouren/Ismaning-Erding-Ebersberg_20200428/20200428_110728-me.jpg" 2>&1

[2020-07-05 18:49:27]  [DEBUG]  [i.php]  
  src_path: '20200428_110728.jpg'
  derivative_path: '20200428_110728-me.jpg'
  o_size: '960 1280 1228800'
  d_size: '445 594 264330'
  mem_usage: 1.0
  timing: array(
    'load' => 40,
    'rotate' => '',
    'crop' => '',
    'scale' => 0,
    'sharpen' => '',
    'watermark' => '',
    'save' => 109,
    'send' => 0,
    'total' => 151,
  )

which also seem to indicate that width & height are set correctly. Still, the resulting image is incorrect. See e.g. http://www.feuster.com/piwigo/picture?/ … _28042020.

I'm really running out of ideas here. Any help appreciated!

Offline

 

#13 2020-07-05 19:37:16

TheDoc
Member
Munich / Germany
2015-10-18
173

Re: Image rotation - once again

Some more info:

When I force the graphics library to "gd" the images are shown correctly!

Unfortunately, there seems to be no "[DEBUG]    [i.php]    convert" output for the gd library. But at least some thing to dig further...

Offline

 

#14 2020-07-06 21:08:24

TheDoc
Member
Munich / Germany
2015-10-18
173

Re: Image rotation - once again

NAILED IT

For any poor soul that might run into the same here is the fix:

ISSUE: There a two orientation flags in my metadata! IFD0:Orientation and XMP-tiff:Orientation. IFD0 is set correctly, XMP-tiff indicates rotation is necessary. Imagick (at least 6.9.2) uses the XMP-tiff flag if present.

FIX: Find and change the XMP-tiff flag

Code:

FIND: exiftool.exe -if "defined $xmp:orientation and $ifd0:orientation# ne $xmp:orientation# " -p $filename *.jpg

CHANGE: exiftool.exe "-ifd0:orientation>xmp:orientation" *.jpg

And now I only need to scan and update my 13k images...

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact