I came across a weird situation:
$ gm convert http://i.wp.pl/a/i/tsw/webby_conf.png -resize 600x /tmp/tmp.jpg
produces 599x212 image:
$ gm identify /tmp/tmp.jpg
/tmp/tmp.jpg JPEG 599x212+0+0 DirectClass 8-bit 15.6Ki 0.000u 0:01
I think it's not an expected result, I would expect gm to produce an image 600px width.
My gm version:
$ gm -version
GraphicsMagick 1.4 snapshot-20151212 Q8 http://www.GraphicsMagick.org/
Copyright (C) 2002-2015 GraphicsMagick Group.
Additional copyrights and licenses apply to this software.
See http://www.GraphicsMagick.org/www/Copyright.html for details.
Feature Support:
Native Thread Safe yes
Large Files (> 32 bit) yes
Large Memory (> 32 bit) yes
BZIP yes
DPS no
FlashPix no
FreeType no
Ghostscript (Library) no
JBIG no
JPEG-2000 no
JPEG yes
Little CMS yes
Loadable Modules no
OpenMP yes (201107)
PNG yes
TIFF no
TRIO no
UMEM no
WebP yes
WMF no
X11 no
XML yes
ZLIB yes
Host type: x86_64-unknown-linux-gnu
Configured using the command:
./configure '--prefix=/opt/WP/common.libs' '--without-tiff' '--without-ttf' '--with-x=no' 'LDFLAGS=-L/opt/WP/common.libs/lib' 'CPPFLAGS=-I/opt/WP/common.libs/include'
Final Build Parameters:
CC = gcc -std=gnu99
CFLAGS = -fopenmp -g -O2 -Wall -pthread
CPPFLAGS = -I/opt/WP/common.libs/include -I/usr/include/libxml2
CXX = g++
CXXFLAGS = -pthread
LDFLAGS = -L/opt/WP/common.libs/lib
LIBS = -lwebp -llcms2 -ljpeg -lpng16 -llzma -lbz2 -lxml2 -lz -lm -lgomp -lpthread
Strange things happen when I use C++ API:
image.resize(Geometry(600,0))produces 600x212 image whileimage.resize(Geometry(600,212))produces 599x212 image.On Wed, 2 Mar 2016, "Przemysław Sobala" wrote:
Please read the documentation. The specified size is a maximum limit
and by default the original aspect ratio is preserved.
The resize geometry in the gm utility is different than in Magick++.
In Magick++ there are fewer geometry "features". Please see the
documentation for Geometry in Magick++. I think that it is pretty
well specified.
Bob
--
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
On Wed, 2 Mar 2016, Przemysław Sobala wrote:
There was previously a bug report regarding this. The reason is
because GraphicsMagick preserves the aspect ratio of the original
image.
Bob
--
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
Related
Bugs: #356
Original image:
260x92 = 2,82608695652
Ouput image:
599x212 = 2,82547169811
I don't call it 'preserved'.
I would suspect GraphicsMagick, after supplying only the width, to do something like:
outHeight = round(92 / 260 * 600) = 212
Last edit: Przemysław Sobala 2016-03-02
Another question regarding C++ API:
image.resize(Geometry(600,600)) produces 600x212
image.resize(Geometry(600,212)) produces 599x212
image.resize(Geometry(600,0)) produces 600x212
Where does this inconsistency come from?
On Wed, 2 Mar 2016, "Przemysław Sobala" wrote:
Geometry(600,0) is equivalent to Geometry(600,600) so the width of the
bounding box is larger.
Bob
--
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
OK, but I still don't understand why does
Geometry(600,600)give a valid size of 600x212 whenGeometry(600,212)give 599x212 (just like 600x212 was invalid - wrong aspect).I can handle this by turning off keeping aspect in
Geometryand calculate output height from:outHeight = outWidth / inAspect, but it should be a default behaviour.And returning back to
gmutility, to quote documentation:From the user view, if I set a width of 600 and leave height unspecified I can assume that the output image would have a width of 600 (not 599).
On Wed, 2 Mar 2016, "Przemysław Sobala" wrote:
I agree that this would be the user's expectation. The user may
expect the value they specify to take priority over preserving the
aspect ratio. Currently the aspect ratio seems to have priority.
Remember that the unit of dimension is in pixels.
The current math may be found in the function
GetMagickGeometry() in magick/utility.c.
I am at work right now and there are other outstanding issues which
might keep me from looking at this for weeks. Please take a look at
the existing code and suggest a change which meets the documented
requirements.
Bob
--
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
One more question about decoder hinting: Why does image size increses sometimes after hinting:
And the output has 208x300 but I would expect it fits inside a 175x175 rectangle
On Thu, 17 Mar 2016, "Przemysław Sobala" wrote:
When used with JPEG, the size hint causes the JPEG library to return
the next larger resolution it supports which is no smaller than the
size specified (if it can), otherwise it returns what it has. The
effect is the opposite of GraphicsMagick -resize, which tries to fit
the image into the resize geometry (i.e. "no larger than" rather than
"larger than").
Bob
--
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/