Skip to content

Use loadFromFile instead of loadFromFileHandle - #34297

Merged
PVince81 merged 1 commit into
masterfrom
fix-preview-image-orientation
Feb 1, 2019
Merged

PVince81 merged 1 commit into
masterfrom
fix-preview-image-orientation

Conversation

@sharidas

Copy link
Copy Markdown
Contributor

Use loadFromFile instead of loadFromFileHandle
while generating the thumbnail.

Signed-off-by: Sujith H [email protected]

Description

When loadFromFileHandle is used for generating thumbnail of images, the problem found is that it doesn't fix the orientation of images with exif. While loadFromFile handles this. It uses exif_imagetype before checking the mimetype of the image file. There is a word of caution noted in the https://github.com/owncloud/core/blob/master/lib/private/legacy/image.php#L496 ( reference: http://php.net/manual/en/function.exif-imagetype.php#79283 ). With the changeset the orientation issue while generating preview is resolved.

Related Issue

Motivation and Context

This changeset fixes the orientation issue of images while generating preview.

How Has This Been Tested?

  • Upload the image mentioned in the issue.
  • The image should be able to view properly ( just like any image viewers like gwenview etc ).

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

Open tasks:

  • Backport (if applicable set "backport-request" label and remove when the backport was done)

Use loadFromFile instead of loadFromFileHandle
while generating the thumbnail.

Signed-off-by: Sujith H <[email protected]>
@sharidas sharidas self-assigned this Jan 29, 2019
@sharidas sharidas changed the title Use loadFromFile instead of loadFromFileHandle [WIP] Use loadFromFile instead of loadFromFileHandle Jan 29, 2019
@sharidas sharidas added this to the development milestone Jan 29, 2019
@codecov

codecov Bot commented Jan 29, 2019

Copy link
Copy Markdown

Codecov Report

Merging #34297 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #34297      +/-   ##
============================================
+ Coverage     64.76%   64.77%   +<.01%     
  Complexity    18368    18368              
============================================
  Files          1199     1199              
  Lines         69550    69550              
  Branches       1281     1281              
============================================
+ Hits          45044    45050       +6     
+ Misses        24133    24127       -6     
  Partials        373      373
Flag Coverage Δ Complexity Δ
#javascript 53.09% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 66.12% <100%> (ø) 18368 <0> (ø) ⬇️
Impacted Files Coverage Δ Complexity Δ
lib/private/Preview/Image.php 87.5% <100%> (ø) 5 <0> (ø) ⬇️
lib/private/legacy/image.php 48.06% <0%> (+1.15%) 170% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7201f89...dc922c1. Read the comment docs.

1 similar comment
@codecov

codecov Bot commented Jan 29, 2019

Copy link
Copy Markdown

Codecov Report

Merging #34297 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #34297      +/-   ##
============================================
+ Coverage     64.76%   64.77%   +<.01%     
  Complexity    18368    18368              
============================================
  Files          1199     1199              
  Lines         69550    69550              
  Branches       1281     1281              
============================================
+ Hits          45044    45050       +6     
+ Misses        24133    24127       -6     
  Partials        373      373
Flag Coverage Δ Complexity Δ
#javascript 53.09% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 66.12% <100%> (ø) 18368 <0> (ø) ⬇️
Impacted Files Coverage Δ Complexity Δ
lib/private/Preview/Image.php 87.5% <100%> (ø) 5 <0> (ø) ⬇️
lib/private/legacy/image.php 48.06% <0%> (+1.15%) 170% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7201f89...dc922c1. Read the comment docs.

@PVince81

Copy link
Copy Markdown
Contributor

seems to make sense, I was expecting something more complicated when I looked into this. It was probably because I took a different route based on git log / diff / bisect and tried to understand the commits that caused the regression.

if this fulfils all use cases as tested in the ticket, and doesn't cause additional performance impact (see local storage vs ext storage), then it should be fine

@sharidas sharidas changed the title [WIP] Use loadFromFile instead of loadFromFileHandle Use loadFromFile instead of loadFromFileHandle Jan 31, 2019
@jvillafanez

Copy link
Copy Markdown
Member

I guess to generate a preview we still need the whole file, even thought I'd still prefer to use streams...
Any idea how many changes are needed to use streams? If there are a lot of changes required, I'm fine with this solution.

@PVince81

PVince81 commented Feb 1, 2019

Copy link
Copy Markdown
Contributor

@jvillafanez I think we never used streams before because many of the PHP functions for image processing operate directly on files, like changing orientation. We definitely need to look into improving this, it might require searching for new libraries.

@PVince81 PVince81 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 looks good and thanks for the extensive tests in the original ticket

@PVince81
PVince81 merged commit ba74089 into master Feb 1, 2019
@delete-merged-branch
delete-merged-branch Bot deleted the fix-preview-image-orientation branch February 1, 2019 06:45
@PVince81

PVince81 commented Feb 1, 2019

Copy link
Copy Markdown
Contributor

@sharidas please backport

@sharidas

sharidas commented Feb 1, 2019

Copy link
Copy Markdown
Contributor Author

Backport to stable10 #34356

@lock lock Bot locked as resolved and limited conversation to collaborators Feb 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OC_Image doesn't always set imageType correctly

4 participants