Page 1 of 1
Convert image to fit fixed size, but black?
Posted: 2012-04-02T02:10:29-07:00
by ultranerds
Hi,
I've got a bit of a weird one here
I'm running the following command:
`mogrify -resize 100x100 -background white -gravity center -extent 100x100 -format jpg -quality 75 "$WriteImage"`;
This is the image before:
http://designerstaticfiles.com.nmsrv.com/before.jpg
And this is it after:
http://designerstaticfiles.com.nmsrv.com/test.jpg
For some reason the suypposidly "white" background comes out as blak ... any ideas? (oh, and it doesn't seem to centralize the image either, so not sure whats going on :/)
TIA
Andy
Re: Convert image to fit fixed size, but black?
Posted: 2012-04-02T04:54:00-07:00
by Bonzo
What version of Imagemagick are you using?
Worked OK for me with convert - does it work for you using convert?
Re: Convert image to fit fixed size, but black?
Posted: 2012-04-02T05:20:16-07:00
by ultranerds
Hi,
Thanks for your reply. I've emailed the guy to ask him to send me SSH access. I can't check version numbers without
He told me that he installed this lot, but didn't say what versions:
imagemagick
imagemagick-C++
imagemagick-C++-devel
imagemagick-devel
imagemagick-perl
Should my command above also work with "convert" instead of "mogrify"? I was just using some examples I found online <G>
Cheers
Andy
Re: Convert image to fit fixed size, but black?
Posted: 2012-04-02T06:14:13-07:00
by Bonzo
You can try hard coding everything to see if it works:
Code: Select all
convert input.jpg -resize 100x100 -background white -gravity center -extent 100x100 -format jpg -quality 75 $WriteImage
If you are using php check out my site for some examples - link below.
Using php you can find the version using:
Code: Select all
<?php
echo "<pre>";
system("convert -version");
echo "</pre>";
?>
Re: Convert image to fit fixed size, but black?
Posted: 2012-04-02T09:40:28-07:00
by ultranerds
Hi,
Thanks for the reply. Its coming up with:
Version: ImageMagick 6.2.8 02/22/12 Q16 file:/usr/share/ImageMagick-6.2.8/doc/index.html
Copyright: Copyright (C) 1999-2006 ImageMagick Studio LLC
I've also tried using that syntax with "convert", and that also has the black stuff showing (which is why I'm getting confused as to whats going on :/)
TIA
Andy
Re: Convert image to fit fixed size, but black?
Posted: 2012-04-02T10:13:44-07:00
by Bonzo
I would guess your version is to old; try:
Code: Select all
convert -size 100x100 xc:red before.jpg -resize 100x100 -unsharp 1.5x1+0.7+0.02 -gravity center -composite -quality 75 output1.jpg
Added some sharpening as well and for some reason -background would not work so had to use xc:
Re: Convert image to fit fixed size, but black?
Posted: 2012-04-02T10:21:26-07:00
by fmw42
According to
http://www.imagemagick.org/Usage/crop/#extent
"Before IM version v6.3.2, "-extent" just cleared the memory of any new areas to zero, or straight black. It did not fill the areas with "-background" color. ... Also after IM v6.3.2, "-extent" will use the "-gravity" to define where the areas added/removed are positioned relative to the original image."
Your version 6.2.8 is too old to use extent and get the background and centering you need.
try
convert -size 100x100 xc:white <yourimage> -resize 100x100 -gravity center -compose over -composite -quality 75 <resultimage>
Re: Convert image to fit fixed size, but black?
Posted: 2012-04-02T10:22:04-07:00
by ultranerds
YOU LEGEND! I was literally pulling my hair out over this one (whats left of it
) ... your solution works like a charm. Thanks for taking the time to help me out
Cheers
Andy
Re: Convert image to fit fixed size, but black?
Posted: 2012-04-02T21:02:00-07:00
by anthony
ultranerds wrote:Hi,
Thanks for your reply. I've emailed the guy to ask him to send me SSH access. I can't check version numbers without
He told me that he installed this lot, but didn't say what versions:
imagemagick
imagemagick-C++
imagemagick-C++-devel
imagemagick-devel
imagemagick-perl
Should my command above also work with "convert" instead of "mogrify"? I was just using some examples I found online <G>
Cheers
Andy
That looks like 'package' installations for a linux system (like fedora, redhat, centos) these system are often out of date, especiually the larger servers whcih don't update packages, as they prefer 'stablity' as in 'old'.
Very old versions of extent did not provide background color, or gravity usage.
The equivelent is to generate a background image yourself and center compose the image over it. Just such a method was shown by Fred (see previous post).
However as typically you want to preverse the images meta-data (labels, comments, camera profiles) other, less direct, methods are typically used. These are exampled in IM Examples, Thumbnails, Padding.
http://www.imagemagick.org/Usage/thumbnails/#pad
Re: Convert image to fit fixed size, but black?
Posted: 2012-04-02T23:36:43-07:00
by ultranerds
Hi,
Thanks for the reply. Yeah the person isn't very server savvy, and therefore just uses Plesk/CPanel to install this kinda stuff. All working now, so all good
Cheers
Andy