PNG or JPG to ICO, not squared.

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Phate
Posts: 4
Joined: 2011-03-29T12:12:36-07:00
Authentication code: 8675308

PNG or JPG to ICO, not squared.

Post by Phate »

Hello everybody.
I have a little problem, and i'm pretty sure there's a solution.
I'm trying to convert a lot of movie covers to ICO format. The command i use is:

convert -resize 256x256 movie.jpg movie.ico

It converts fine, but the resulting icon is squared and not rectangular like a dvd cover. Is there an option that i need to add?
The result i'm looking for is the same result this site gives: http://converticon.com/
But i need to be able to do this from the command line because i need it for a script i'm writing.
Thank you :).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG or JPG to ICO, not squared.

Post by fmw42 »

Post a link to one of your images that needs converting to non-square format.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: PNG or JPG to ICO, not squared.

Post by Bonzo »

I thought ico files were always square; it may be something built into the format?

If so try padding the image to make it square before resizing it.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: PNG or JPG to ICO, not squared.

Post by Bonzo »

My mistake - just tried it and works OK on a rectangular file.

Your command is slightly wrong and should be:

Code: Select all

convert movie.jpg -resize 256x256 movie.ico
Looking at the thumbnail in windows it looks square but when you click on it to open it is rectangular - strange.
Phate
Posts: 4
Joined: 2011-03-29T12:12:36-07:00
Authentication code: 8675308

Re: PNG or JPG to ICO, not squared.

Post by Phate »

Bonzo wrote:My mistake - just tried it and works OK on a rectangular file.

Your command is slightly wrong and should be:

Code: Select all

convert movie.jpg -resize 256x256 movie.ico
Looking at the thumbnail in windows it looks square but when you click on it to open it is rectangular - strange.
That's exactly my problem. When you set that icon as a folder icon it looks squared, while using an icon created with the site in the first post it looks fine. I need it rectangular for setting the icon in every folders in my movie's directory, and there are quite a few :).
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: PNG or JPG to ICO, not squared.

Post by Bonzo »

I would say you need to add extent to pad the image square with either a transparent or white background and then resize it.
Phate
Posts: 4
Joined: 2011-03-29T12:12:36-07:00
Authentication code: 8675308

Re: PNG or JPG to ICO, not squared.

Post by Phate »

Bonzo wrote:I would say you need to add extent to pad the image square with either a transparent or white background and then resize it.
I tried adding a transparent padding with photoshop and it worked, have you any ideas on how to do this in imagemagick? Great tip by the way, at least now i have something to try :).
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: PNG or JPG to ICO, not squared.

Post by Bonzo »

If all you images are the same size it is easier but can be calculated with the fx command. How are you running the command windows command, batch, linux, shell etc?

Try this the dimensions of extent need to be correct for the original image ( in this case the original image would be 500px high ):

Code: Select all

convert input.jpg -background transparent -gravity center -extent 500x500 -resize 256x256 movie.ico
Phate
Posts: 4
Joined: 2011-03-29T12:12:36-07:00
Authentication code: 8675308

Re: PNG or JPG to ICO, not squared.

Post by Phate »

Bonzo wrote:If all you images are the same size it is easier but can be calculated with the fx command. How are you running the command windows command, batch, linux, shell etc?

Try this the dimensions of extent need to be correct for the original image ( in this case the original image would be 500px high ):

Code: Select all

convert input.jpg -background transparent -gravity center -extent 500x500 -resize 256x256 movie.ico
Thank you very much! It works wonder :D.
It will be launched by a script in powershell, a pretty easy one. Resizing an image before running this command is no problem. It will be something like this:

Code: Select all

foreach (element in ls) {
	convert .\element\movie.png -resize x500 .\element\movie.png
	convert .\element\movie.png -background transparent -gravity center -extent 500x500 -resize 256x256 .\element\movie.ico
	rm movie.png
	cp C:\Desktop.ini .\element
}
Where in Desktop.ini are all the info on setting the folder's icon. Thank you again, you saved me a lot of time :).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG or JPG to ICO, not squared.

Post by fmw42 »

convert input.jpg -background transparent -gravity center -extent 500x500 -resize 256x256 movie.ico
Seems to me, to be more efficient, that you want to resize then pad, if you want it to be square.

convert input.jpg -resize 256x256 -background transparent -gravity center -extent 256x256 movie.ico

but then I don't know much about ico files.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: PNG or JPG to ICO, not squared.

Post by anthony »

For methods of padding images and thumbnails see IM examples, Thumbnailling
http://www.imagemagick.org/Usage/thumbnails/#pad
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply