Image Scale Help

"Please leave a message at the beep, we will get back to you when your support contract expires."

Moderators: phlip, Moderators General, Prelates

yewbie
Posts: 208
Joined: Mon Sep 13, 2010 6:35 pm UTC

Image Scale Help

Postby yewbie » Fri Apr 22, 2011 6:09 pm UTC

I have a couple hundred PNG files that are all at a relative scale of 40x40 (the size of 1 of my tiles) I want them to be scaled to 64x64.

Now this is easy enough to do with a single 40x40 pixel image.

But there are some images that are larger for instance 240x260, I am looking for a way to indiscriminately scale all of these images by the same ratio to make cutting them into my 64x64 images easier.

Also this is for a game project im working on using a public domain tileset called Lostgarden.

Maintaining the scale has to be perfect so that for instance I have 7 images of varying sizes that when combined make up the whole structure of say a house, right now they are at the scale of a 40x40 (this is relative I guess) but it needs to be 64x64.

I guess I could just manually combine all of the various file to the combined final product, scale it to whatever looks good to me, and then cut it out into my tiles, but if anyone has any suggestions it would be greatly appreciated!

yewbie
Posts: 208
Joined: Mon Sep 13, 2010 6:35 pm UTC

Re: Image Scale Help

Postby yewbie » Fri Apr 22, 2011 9:24 pm UTC

Basically unless someone can find a better way, I am scaling the canvas by multiples of 40 whatever fits everything in, then I am just upscaling everything by multiples of 64, IE: 40x3 = 120, so 120 = 3*64 = 192 so I just scale 120 to 192, it works but man its a PITA to do this on a couple hundred files.

User avatar
cerbie
Posts: 934
Joined: Sat Jul 05, 2008 5:14 am UTC
Location: USA

Re: Image Scale Help

Postby cerbie » Fri Apr 22, 2011 9:35 pm UTC

A. Do you mean that you need to scale them to the next multiple of 64? Or, do you mean everything*1.6?
B. How can you make an image upscaled like that not look crap, regardless of how it looks at 40x040?
C. Is there a reason you can't script the operation, with Lua, Python, or PHP (using Imagemagick for the legwork)?
DSenette: (...) on the whole, even a trained killer cow is kind of stupid.

yewbie
Posts: 208
Joined: Mon Sep 13, 2010 6:35 pm UTC

Re: Image Scale Help

Postby yewbie » Fri Apr 22, 2011 9:50 pm UTC

cerbie wrote:A. Do you mean that you need to scale them to the next multiple of 64? Or, do you mean everything*1.6?

Everything 1.6

cerbie wrote:B. How can you make an image upscaled like that not look crap, regardless of how it looks at 40x040?

a 40x40 texture upscaled to 64x64 doesn't look that terrible considering its only being used in a 64x64 context and not being scaled again

g-mm.png
g-mm.png (2.18 KiB) Viewed 1021 times

5.png
5.png (7.83 KiB) Viewed 1021 times



cerbie wrote:C. Is there a reason you can't script the operation, with Lua, Python, or PHP (using Imagemagick for the legwork)?

Basically knowledge is the only thing stopping me there, I was hoping someone had a handy little script I could run to do exactly this, I will look up imagemagick and see what I can do.

User avatar
Jorpho
Posts: 6279
Joined: Wed Dec 12, 2007 5:31 am UTC
Location: Canada

Re: Image Scale Help

Postby Jorpho » Sat Apr 23, 2011 5:03 am UTC

There's a tutorial for the Python Image Library here:
http://www.pythonware.com/library/pil/h ... uction.htm

Maybe you can adapt one of the examples to your needs?

User avatar
diabolo
Posts: 72
Joined: Fri Aug 08, 2008 4:17 pm UTC
Location: france

Re: Image Scale Help

Postby diabolo » Sat Apr 23, 2011 7:19 am UTC

yewbie wrote:Basically knowledge is the only thing stopping me there, I was hoping someone had a handy little script I could run to do exactly this, I will look up imagemagick and see what I can do.

ImageMagick has convert to resize and stuff from the command line.
So to scale image.png by 1.6 you can do

Code: Select all

convert -scale 160% image.png new-image.png

That should work ok (except maybe if you need absolute control over the rounding of the values?)

Then you just need to script that so it runs on all you files.
Spoiler:
I tried it on your images and a few icons I had laying around using ls and xargs

Code: Select all

$ ls
    accept.png  action_go.png  flag.png  scaled  yewbie_5.png  yewbie_g-mm.png
$ identify -format "%f : %Wx%H\n" *.png
    accept.png : 16x16
    action_go.png : 16x16
    flag.png : 16x11
    yewbie_5.png : 64x64
    yewbie_g-mm.png : 40x40

$ mkdir scaled
$ ls *.png | xargs -I{} convert -scale 160% {} scaled/{}
$ identify -format "%f : %Wx%H\n" scaled/*.png
    accept.png : 26x26
    action_go.png : 26x26
    flag.png : 26x18
    yewbie_5.png : 102x102
    yewbie_g-mm.png : 64x64


User avatar
phlip
Restorer of Worlds
Posts: 7572
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Image Scale Help

Postby phlip » Sat Apr 23, 2011 1:51 pm UTC

Note that if you've got, as it sounds like, a large image that's a bunch of different 40x40 tiles stitched together, which you cut into individual tiles later in your program... then simply scaling the image up by a factor of 64/40 isn't going to do what you want, most likely. If you have any sort of interpolation turned on, you're going to end up with artefacts around the edges of the tiles, where it's interpolating from one tile into the next. And if you don't have any interpolation at all (just nearest neighbour) then a factor like 64/40 is just going to look ugly.

The most complete option is going to be to cut the larger images into their component 40x40 tiles, scaling each one individually up to 64x64, and then stitching it all together again. Each of those steps can be done with ImageMagick and a little scripting, if you want to go that route.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
cerbie
Posts: 934
Joined: Sat Jul 05, 2008 5:14 am UTC
Location: USA

Re: Image Scale Help

Postby cerbie » Sat Apr 23, 2011 4:20 pm UTC

OK, now:

1. You mentioned 240x260 as an example of an image off from the scale. How are you going to handle these? Adjust the ratio? Ignore the extra 20px?

2. If Python is fine, try learning it a bit, and using the imaging library. Try taking some tiles with edges drawn on them, and see if there are significant differences between (a) your image editor of choice, (b) bilinear, and (c) bicubic. If neither of the latter two look good, you can chop up images with such a script, then have a simple Imagemagick script run over the rest, as I know imagemagick's default scaling is quite good (convert -scale 64x64...).

If PIL can work out, that's probably the best route. Python is among the easiest languages for beginners.
DSenette: (...) on the whole, even a trained killer cow is kind of stupid.

yewbie
Posts: 208
Joined: Mon Sep 13, 2010 6:35 pm UTC

Re: Image Scale Help

Postby yewbie » Mon Apr 25, 2011 3:27 pm UTC

cerbie wrote:OK, now:
1. You mentioned 240x260 as an example of an image off from the scale. How are you going to handle these? Adjust the ratio? Ignore the extra 20px?

Yeah, they still adhere to the 40x40 aspect ratio they just have extra blank space, I was going to manually cut them into my tiles because of this after changing the scale.

cerbie wrote:2. If Python is fine, try learning it a bit, and using the imaging library. Try taking some tiles with edges drawn on them, and see if there are significant differences between (a) your image editor of choice, (b) bilinear, and (c) bicubic. If neither of the latter two look good, you can chop up images with such a script, then have a simple Imagemagick script run over the rest, as I know imagemagick's default scaling is quite good (convert -scale 64x64...).

Yeah, thanks for the help, I have imagemagick setup I was playing with it, I was having some problems with the scaling, but I managed to get them resolved.

Thanks for the help everyone, you have made this alot easier =p


Return to “The Help Desk”

Who is online

Users browsing this forum: No registered users and 6 guests