Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inverted thumbnail ratio with orientation in source, ImageMagick (convert) engine #618

Closed
challet opened this issue Jan 30, 2020 · 1 comment · Fixed by #619
Closed

Inverted thumbnail ratio with orientation in source, ImageMagick (convert) engine #618

challet opened this issue Jan 30, 2020 · 1 comment · Fixed by #619

Comments

@challet
Copy link
Contributor

challet commented Jan 30, 2020

Hello,

When a file needing a orientation change is made into a thumbnail, the aspect ratio is not inverted during the -scale operation. Leading to a distorsion in the result.

Scenario

  • source image (orientation 6, size 1800x1200). 1200 being the height of the not re-oriented source image and the width of the intermediate (1200x1800) re-oriented image:
  • get_thumbnail(source_img, 600). Which should result, taking the orientation into account, to a 600x900 full geometry
  • the convert command is actually called with convert sourcefile -auto-orient -colorspace RGB -scale 600x400! -interlace line -quality 95 thumbfile
  • leading to the final image : 69b40b75d5bcc7f77bb0b73b08bd3f83

Additional note

  • the dimensions seem to be reversed during a set_size but not at scale operation time
    • # This is the worst case scenario
      image = default.engine.get_image(self)
      size = default.engine.get_image_size(image)
      if self.flip_dimensions(image):
      size = list(size)
      size.reverse()
      self._size = list(size)
    • def flip_dimensions(self, image, geometry=None, options=None):
      options = options or {}
      reoriented = hasattr(self, 'reoriented')
      if options.get('orientation', settings.THUMBNAIL_ORIENTATION) and not reoriented:
      return self._flip_dimensions(image)
      return False
  • I haven't been able to check for the other engines
  • most probably related to the first problem of 2 orientation bugs #495
@challet
Copy link
Contributor Author

challet commented Jan 30, 2020

@unittest.skipIf('pil_engine' not in settings.THUMBNAIL_ENGINE, 'the other engines fail this test')
def test_image_with_orientation(self):
name = 'data/aspect_test.jpg'
item, _ = Item.objects.get_or_create(image=name)
im = ImageFile(item.image)
th = self.BACKEND.get_thumbnail(im, '50x50')
# this is a 100x200 image with orientation 6 (90 degrees CW rotate)
# the thumbnail should end up 25x50
self.assertEqual(th.x, 25)
self.assertEqual(th.y, 50)

Just saw a test with the exact same issue. It has been skipped with the reason "the other engines fail this test" and fixed for the pillow engine in #455.

@challet challet changed the title Inverted ratio thumbnail with source orientation, ImageMagick (convert) engine Inverted thumbnail ratio with orientation in source, ImageMagick (convert) engine Jan 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant