digitalascetic / ngx-pica

@digitalascetic/ngx-pica is an Angular(LTS) module to resize images files in browse
36 stars 26 forks source link

Image rotated when it's not needed #34

Closed miqm closed 4 years ago

miqm commented 4 years ago

Hello,

I've a small issue with the exif rotation. I'm using ngx-pica to shrink images taken from mobile. However, when taking a photo in portrait mode, in addition to the exif orientation being set to 6, image has already proper dimensions (height > width).

In result, image after resizing is back in landscape mode.

I've tested this on Sony Z5 and iPhone SE - same results.

Could I suggest adding some option to resizer to disable the exif orientation detection and/or a check for (height > width) so rotation will not occur?

edezacas commented 4 years ago

Hello @miqm ,

Can you give us an example about it? What are you trying to do? Resize, compress?

miqm commented 4 years ago

@edezacas - resize.

edezacas commented 4 years ago

Have you tried to pass NgxPicaResizeOptionsInterface to resizeImage method? For example aspectRatio.keepAspectRatio = false?

miqm commented 4 years ago

Yes, no result.

Problem is that when image goes out of the exif "rotation" it's being to rotated again, resulting image being displayed horizontal instead portrait.

Reason I thinnk is that camera creates image in proper shape. Not like in the old days, camera output was "horizontal" and only EXIF value indicated that it's portrait, but now it's in proper orientation plus exif is set to 'portrait'.

So the exif rotation method gets already rotated image and rotates it again. Of course for some pictures, rotation might be needed, so basically there isn't a good way of determining if image is properly oriented or not.

here' some sample:

<img [src]="photo"></img>
<input  type="file" accept="image/*" capture="environment" (change)="onPhotoAdded($event.target.files)"></input>
this.imgResize.resizeImage(fileList[i], 2048, 1536).subscribe(x => {this.photo = URL.createObjectURL(x as File);});

My request is that we should give developer freedom, if he want's to use the exif rotation when resizing or not.

edezacas commented 4 years ago

It's a good suggestion, but in the example above you are resizing to landscape mode with a width as 2048 and height 1536.

miqm commented 4 years ago

Yes, but those are maximum values (if i use keep aspect ratio, which I do)

miqm commented 4 years ago

Here's a sample portrait image that I'm using for testing: image

Please note, that basically, this is not a bug. I'm just opting for possibility to disable the automatic exif rotation, as in some cases it might not be desired. At the end, only user is able to verify, if image is in proper orientation.

edezacas commented 4 years ago

We've just released a new version improving this feature, now for resize or compress methods we've the possibility to set exifOptions.forceExifOrientation to false, to avoid rotate image.