Results 1 to 8 of 8

Thread: Imagemagick help (well really a DOS scripting question)

  1. #1
    Community Leader Facebook Connected torstan's Avatar
    Join Date
    Jul 2007
    Posts
    4,199

    Help Imagemagick help (well really a DOS scripting question)

    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

  2. #2
    Community Leader jfrazierjr's Avatar
    Join Date
    Oct 2007
    Location
    Apex, NC USA
    Posts
    3,057

    Post

    Quote Originally Posted by torstan View Post
    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.)
    My Finished Maps
    Works in Progress(or abandoned tests)
    My Tutorials:
    Explanation of Layer Masks in GIMP
    How to create ISO Mountains in GIMP/PS using the Smudge tool
    ----------------------------------------------------------
    Unless otherwise stated by me in the post, all work is licensed under a Creative Commons Attribution-Noncommercial 3.0 United States License.

  3. #3
    Community Leader Facebook Connected torstan's Avatar
    Join Date
    Jul 2007
    Posts
    4,199

    Post

    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.

  4. #4
    Administrator Redrobes's Avatar
    Join Date
    Dec 2007
    Location
    England
    Posts
    7,193
    Blog Entries
    8

    Post

    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.

  5. #5
    Community Leader jfrazierjr's Avatar
    Join Date
    Oct 2007
    Location
    Apex, NC USA
    Posts
    3,057

    Default

    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.
    My Finished Maps
    Works in Progress(or abandoned tests)
    My Tutorials:
    Explanation of Layer Masks in GIMP
    How to create ISO Mountains in GIMP/PS using the Smudge tool
    ----------------------------------------------------------
    Unless otherwise stated by me in the post, all work is licensed under a Creative Commons Attribution-Noncommercial 3.0 United States License.

  6. #6
    Community Leader Facebook Connected torstan's Avatar
    Join Date
    Jul 2007
    Posts
    4,199

    Post

    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:

    Code:
    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.
    Last edited by torstan; 03-27-2009 at 06:59 PM.

  7. #7
    Administrator Redrobes's Avatar
    Join Date
    Dec 2007
    Location
    England
    Posts
    7,193
    Blog Entries
    8

    Post

    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.

  8. #8
    Community Leader Facebook Connected torstan's Avatar
    Join Date
    Jul 2007
    Posts
    4,199

    Post

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •