Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

.autoOrient() doesn't work with .thumb() #99

Closed
ARAtlas opened this Issue · 5 comments

4 participants

@ARAtlas

I need to create thumbnails of images that may be EXIF-rotated. I tried sticking an .autoOrient() before the .thumb() call like this:

imageMagick('public/images/'+originalImage)
  .autoOrient()
  .thumb(size, size, 'public/images/'+thumbImage, quality, 'center', function(err) {

When I do that, the output image re-orients correctly, but now the thumbnail is squashed-to-square instead of cropped-to-square. Is this a bug or am I missing something?

@aheckmann
Owner

Not sure, both thumb and autoOrient are sugar and involve several calls to graphicsmagick which may not play perfectly well together. It should be easy to track down what this issue is by just executing the code inline and playing with the options that are used.

If thumb doesn't work right without autoOrient that could be related to changes made in 1.6 and how size is calculated: https://github.com/aheckmann/gm/blob/master/lib/convenience/thumb.js#L21

Let me know what you find out.

@dncrews

autoOrient doesn't play well with resize(), either. To get it to do both, I have to do an orient, and then a write, like this: (coffeescript)

img = im(path).autoOrient().write path, (err) ->
    if err
        return console.log err
    img = im(path)
    img.resize(200, 200).write newPath, (err) ->
        if err
            return console.log err
        # success code

I wonder if this is only an issue because both me and OP are using the ImageMagick subClass...?

@ARAtlas

The problem appears to be that autoOrient() somehow clears out the options set by thumb(). If I run thumb() alone, then this is the arguments that get used:

"-quality" "80" "public/images/7b96fdc5f296fedecdb1bdb9c191bb25/image.jpg" "-scale" "133x100" "-crop" "100x100+16.5+0" "+profile" "\"*\"" "public/images/7b96fdc5f296fedecdb1bdb9c191bb25/image_100x100.jpeg"

However, if I chain in an autoOrient().thumb(), and then hold my phone in such a way that no rotation is necessary, then these arguments get used:

convert "public/images/a7728a4ca56ad238721459961fc36f45/image.jpg" "public/images/a7728a4ca56ad238721459961fc36f45/image_100x100.jpeg"

If I chain autoOrient().thumb(), and hold my phone at a 90 degree angle, these arguments get used:

"public/images/2c263cc7fc55edee15e7e3ae2e66649c/image.jpg" "-rotate" "90" "-page" "+0+0" "+profile" "\"*\"" "public/images/2c263cc7fc55edee15e7e3ae2e66649c/image_100x100.jpeg"

Again, these arguments are ones set by autoOrient(), with none of the options set by thumb() making it through to the end.

@JNissi JNissi referenced this issue from a commit in JNissi/gm
@JNissi JNissi Avoid losing already set arguments on identify.
When we exec identify, we don't want to lose the options set for the other commands that will come after identify.

This should fix autoOrient (calls orientation, which in turn execs identify) acting up as in #99
28bfe94
@aheckmann aheckmann closed this issue from a commit
@aheckmann tests; add autoOrient + thumb() test
closes #99
fix was in #105
1344dcd
@aheckmann aheckmann closed this in 1344dcd
@aheckmann
Owner

fix is in 1.8.1

@danieldkim

this is still an issue for me. i'm on 1.8.1 and the arguments are no longer being lost the but the final generated command does not produce the intended result.

i have some coffescript that does this:

gm(filePath).
  autoOrient().
  setFormat('jpeg').
  gravity('Center').
  thumb width, height, outPath, quality, (err) => next err, outPath

with a portrait image and width and height both equal to 213, this command is generated:

gm "convert" "-quality" "90" "-size" "285x213" "/tmp/foo.jpg" "-rotate" "90" "-page" "+0+0" "+profile" "\"*\"" "-gravity" "Center" "-scale" "285x213" "-crop" "213x213+0+0" "+profile" "\"*\"" "/tmp/foo-thumb.jpg"

the final image is not cropped, however. removing the "-scale" option fixes the issue. this command produces the proper thumb:

gm "convert" "-quality" "90" "-size" "285x213" "/tmp/foo.jpg" "-rotate" "90" "-page" "+0+0" "+profile" "\"*\"" "-gravity" "Center" "-crop" "213x213+0+0" "+profile" "\"*\"" "/tmp/foo-thumb.jpg"

i'm not sure why the "-scale" option is only an issue when auto-orienting but that's the behavior i'm observing.

@dpup dpup referenced this issue from a commit
@JNissi JNissi Avoid losing already set arguments on identify.
When we exec identify, we don't want to lose the options set for the other commands that will come after identify.

This should fix autoOrient (calls orientation, which in turn execs identify) acting up as in #99
380362b
@dpup dpup referenced this issue from a commit
@aheckmann tests; add autoOrient + thumb() test
closes #99
fix was in #105
6bc1ed0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.