Weird "border" with jpegtran when rotating an image

173 Views Asked by At

I'm using jpegtran to rotate my images, but it seems to be doing some weird stuff. The same code/logic worked on my other server. Here is a test case I've done:

test.jpg is the original image, then I run:

jpegtran -rotate 90 test1.jpg > test2.jpg.tmp
mv test2.jpg.tmp test2.jpg
jpegtran -rotate 90 test2.jpg > test3.jpg.tmp
mv test3.jpg.tmp test3.jpg

test.jpg:

test1.jpg

test2.jpg

test2.jpg (first rotation)

test3.jpg:

test3.jpg (2nd rotation)

As you should be able to see, there are weird borders on it (almost like shadows on another part of the image):

enter image description here

What would cause this, and how can I get around it?

The OLD server shows:

jpegtran -v
libjpeg-turbo version 1.2.1 (build 20131209)
Copyright (C) 1991-2010 Thomas G. Lane, Guido Vollbeding
Copyright (C) 1999-2006 MIYASAKA Masaru
Copyright (C) 2009 Pierre Ossman for Cendio AB
Copyright (C) 2009-2012 D. R. Commander
Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)

Emulating The Independent JPEG Group's libjpeg, version 6b  27-Mar-1998

...and the NEW server shows:

jpegtran -v
Independent JPEG Group's JPEGTRAN, version 9b  17-Jan-2016
Copyright (C) 2016, Thomas G. Lane, Guido Vollbeding
1

There are 1 best solutions below

0
On

Typically, no sooner had I written the question out and posted it, I found the solution :)

http://www.imagemagick.org/discourse-server/viewtopic.php?t=21341#p87099

Basically, to add "-trim" to the command - so it looks like:

jpegtran -rotate 90 -trim test1.jpg > test2.jpg.tmp
mv test2.jpg.tmp test2.jpg
jpegtran -rotate 90 -trim test2.jpg > test3.jpg.tmp
mv test3.jpg.tmp test3.jpg

I've just tried this out, and it works as expected :) Thought I would post it here in case anyone else comes across this!