PDA

View Full Version : Imagemagick help (well really a DOS scripting question)



torstan
03-27-2009, 05:15 PM
Hey there.

So trying to keep two up to date versions of tiles at 50px and 100px is a pain. Clearly the better plan is to keep the 100px one up to date and then copy and resize this directory whenever I update. I must be able to do this using basic DOS scripts and imagemagick, but I can't figure it out for the life of me.

The imagemagick command is actually pretty straightforward:
mogrify -resize 50% *.png

The one problem I have with this is that it results the correct sized image in pixels, but no real gain in filesize. Any thoughts?

However the real trouble here is the DOS scripting required to run this on a folder and and all of its subdirectories. Any ideas? Any help much appreciated - and rewarded with a healthy dose of rep :)

jfrazierjr
03-27-2009, 05:20 PM
Hey there.

So trying to keep two up to date versions of tiles at 50px and 100px is a pain. Clearly the better plan is to keep the 100px one up to date and then copy and resize this directory whenever I update. I must be able to do this using basic DOS scripts and imagemagick, but I can't figure it out for the life of me.

The imagemagick command is actually pretty straightforward:
mogrify -resize 50% *.png

The one problem I have with this is that it results the correct sized image in pixels, but no real gain in filesize. Any thoughts?

However the real trouble here is the DOS scripting required to run this on a folder and and all of its subdirectories. Any ideas? Any help much appreciated - and rewarded with a healthy dose of rep :)

Are you current tiles sized 100 px for the actual image or the visible image dimensions? I would think that just shrinking from the image borders would not get the snap to grid since it would come up in the wrong location on the grid in Maptool.. Of course, I could be off in lala land (which is typically the case.)

torstan
03-27-2009, 05:24 PM
The tiles are all sized in increments of 100px. So if they are all resized by 50% then they will be in increments of 50px and snap accordingly. This is what I've been doing so far, but resizing each one in Gimp is a royal pain. No more of that say I.

Redrobes
03-27-2009, 05:54 PM
Heres the quick way I would do it.

Do a Dir /s /b and send to a file like this:

DIR /s /b *.png > files.txt

then open files.txt with wordpad and use the search and replace menu option to change all the "C:" (say) to "mogrify -resize 50% C:" i.e. add all that guff to the front.

then rename the file to Change.BAT and run it as a batch script.

For the file size I would check using its other command identify on one before and after sizing. I would expect that the file size would go down but not by half or a quarter. If the file was small in size to start with then the headers for it would be a large proportion of the total and they would not change. Also there are several versions of the IM tool set. Some are 8 bit and some are 16bit per component. Check that the original is not being read as 8 and being saved as a 16. If it is then add a "-depth 8" to the args. If you still cant tell then there is a -verbose option to the identify which prints a few pages of info. Something in there should give you a clue.

Let me know how you get on.

jfrazierjr
03-27-2009, 05:54 PM
Hmmm there was some GIMP plugin that RobA linked to a few months ago that allows batch resizes, but I don't remember if it works on %'s or just hard coded sizes and does all files in a folder.

torstan
03-27-2009, 06:15 PM
Thanks RR.

I'm hitting a few problems though - is % a spacial character in a .bat file? It seems to be killing the following string or two.

Edit: Nevermind - I've found it. There are spaces in the full filenames because windows is like that. I'll see if I can find a way around that.

Edit^2: Done it. Phergus on the rptools boards gave me a DOS command for this, and with a little tweaking I got this which works just dandy:


for /r %i IN (*.png) DO mogrify -resize 50% "%i"

Thanks a lot RR for the thoughts about the imagemagick resizing. The reason I was surprised about the size is because I have the resized version from Gimp and the resized version from imagemagick and the IM versions are significantly larger than the Gimp ones. I'll investigate over the weekend.

Redrobes
03-27-2009, 07:47 PM
Ah yes that would be a better way than I mentioned. The % is a special character I forgot about that too. Thats either, take a parameter or use an environment var depending on context. I think if I were presented with the problem I would have used Perl and perlmagick since you can scan directories in using that too. Anyway, glad its all solved. The line you have is probably the easiest way of doing it of all methods.

torstan
03-27-2009, 08:07 PM
Yep, perl and python are on my to do list and I may well do this in one of those as a baby project to get started, but this does seem to be the easiest solution.