Page 1 of 1
Imagemagick create thumbnail
Posted: 2013-06-15T14:02:43-07:00
by chaoscarnage
I have an image that is 200x200 I want to trim the white space, and make it into an icon that is 32x32.
Code: Select all
convert img.png -trim -resize 32x32 imgi.png
This line of code does not work, it will not make the canvas a uniform 32x32. I have tried taking it and adding -canvas 32x32 or -extend 32x32 but then the script does not work at all.
I am doing this from PHP with exec so I do not get an error back.
Re: Imagemagick create thumbnail
Posted: 2013-06-15T14:05:08-07:00
by Bonzo
Have you tried +repage ?
Code: Select all
convert img.png -trim -resize 32x32 +repage imgi.png
Re: Imagemagick create thumbnail
Posted: 2013-06-15T14:08:42-07:00
by chaoscarnage
I tested repage with both resize and thumbnail. In both cases the image canvas is coming out 9x32. Same was without repage. I read though the examples to come up with what I have now. Trim takes out all of the transparent space, but then the canvas does not reset to 32x32 with the resize.
Re: Imagemagick create thumbnail
Posted: 2013-06-15T14:11:07-07:00
by fmw42
If the white space is not trimmed evenly, then the image will not be square after the trim and your resize will not end up square. You can force it to be 32x32 exactly if you are willing to allow for some distortion from its actual aspect ratio by adding !. Depending upon your OS, you may need to escape the ! or put the argument into double quotes.
convert img.png -trim -resize 32x32! imgi.png
Re: Imagemagick create thumbnail
Posted: 2013-06-15T14:18:44-07:00
by chaoscarnage
I tried that as well and it stretches the result to fit the size. I just want to have the same image but on a 32x32 canvas so all my thumbnails are 32x32.
Re: Imagemagick create thumbnail
Posted: 2013-06-15T14:33:56-07:00
by snibgo
Offering advice is far easier if we can see the image.
If the trimmed image isn't square, you must decide what you want to do: trim some of the image, or add some blank to make it square, or stretch the image.
Re: Imagemagick create thumbnail
Posted: 2013-06-15T14:36:54-07:00
by fmw42
you can fill it with transparency. Your trim is removing a lot of width so that is why it is 9x32.
convert image.png -trim +repage -resize 32x32 -gravity center -background none -extent 32x32 result.png
Re: Imagemagick create thumbnail
Posted: 2013-06-15T14:37:58-07:00
by chaoscarnage
snibgo wrote:Offering advice is far easier if we can see the image.
If the trimmed image isn't square, you must decide what you want to do: trim some of the image, or add some blank to make it square, or stretch the image.
We want to add some transparency to make it square.
Re: Imagemagick create thumbnail
Posted: 2013-06-15T14:39:50-07:00
by fmw42
We want to add some transparency to make it square.
See my post just above yours. We must have posted at about the same time.
Re: Imagemagick create thumbnail
Posted: 2013-06-15T14:41:24-07:00
by chaoscarnage
fmw42 wrote:We want to add some transparency to make it square.
See my post just above yours. We must have posted at about the same time.
That appears to have worked perfectly. Thank you.
Re: Imagemagick create thumbnail
Posted: 2013-06-15T15:14:12-07:00
by fmw42
if you don't like the centering, you can change the gravity setting so that it might end up more aligned as it was originally
Re: Imagemagick create thumbnail
Posted: 2013-07-05T04:53:21-07:00
by chaoscarnage
fmw42 wrote:you can fill it with transparency. Your trim is removing a lot of width so that is why it is 9x32.
convert image.png -trim +repage -resize 32x32 -gravity center -background none -extent 32x32 result.png
POST trim, If the icon is SMALLER than 32x32, I just want to extend and not resize, is there a way to tell it that
Re: Imagemagick create thumbnail
Posted: 2013-07-05T05:41:50-07:00
by GreenKoopa
-resize and its geometry argument is very flexible. Try adding the shrink only flag
convert image.png -trim +repage -resize 32x32> -gravity center -background none -extent 32x32 result.png
The > character may need to be quoted or escaped on your platform. For other flags see:
http://www.imagemagick.org/script/comma ... p#geometry
Re: Imagemagick create thumbnail
Posted: 2013-07-05T05:58:23-07:00
by chaoscarnage
GreenKoopa wrote:-resize and its geometry argument is very flexible. Try adding the shrink only flag
convert image.png -trim +repage -resize 32x32> -gravity center -background none -extent 32x32 result.png
The > character may need to be quoted or escaped on your platform. For other flags see:
http://www.imagemagick.org/script/comma ... p#geometry
That's exactly what I needed thank you very much.