Page 1 of 1

How to double the dimensions of images as long as they don't go above 192X192?

Posted: 2020-03-02T13:25:13-07:00
by tommaniacal
I have a large folder of images and I need to double the size of most of them, however some are already doubled. My question is, is there a way to double the size of all images less than or equal to 96X96, so that all of the images are less than or equal to 192X192 afterwards?

These images are the sprites for a game, so I'd like to double their size without altering the quality at all.

Thank you!

Re: How to double the dimensions of images as long as they don't go above 192X192?

Posted: 2020-03-02T13:57:37-07:00
by snibgo
What version of IM, on what platform?

What is the image format? Please provide a sample input.

Exactly what do you mean by "less than or equal to 96X96"? Is an image 90x100 less that that, or more than that?

It could be done in a single command: clone, and double its size. Then delete one of the images, depending on the size of the clone.

Or do it in a script: find the size, and either double it or don't.

Re: How to double the dimensions of images as long as they don't go above 192X192?

Posted: 2020-03-02T15:49:04-07:00
by fmw42
How do you define no quality change? Any time you change the size of an image, pixels are changed. When doubling you can replicated pixels or you can interpolate new values from the neighbors in the input image. Also if starting from a JPG and saving as JPG, there will be quality changes, since the jpg has a lossy compression. Anytime you read and write to that format, you lose quality.

Re: How to double the dimensions of images as long as they don't go above 192X192?

Posted: 2020-03-02T16:10:20-07:00
by tommaniacal
snibgo wrote:
2020-03-02T13:57:37-07:00
What version of IM, on what platform?

What is the image format? Please provide a sample input.

Exactly what do you mean by "less than or equal to 96X96"? Is an image 90x100 less that that, or more than that?

It could be done in a single command: clone, and double its size. Then delete one of the images, depending on the size of the clone.

Or do it in a script: find the size, and either double it or don't.
Format is .png

here's a sample input: Image

All of the images are square, so they have the same width and height.

I'm not the most experienced in scripting, would you be able to help me with that?

Re: How to double the dimensions of images as long as they don't go above 192X192?

Posted: 2020-03-02T16:13:47-07:00
by tommaniacal
fmw42 wrote:
2020-03-02T15:49:04-07:00
How do you define no quality change? Any time you change the size of an image, pixels are changed. When doubling you can replicated pixels or you can interpolate new values from the neighbors in the input image. Also if starting from a JPG and saving as JPG, there will be quality changes, since the jpg has a lossy compression. Anytime you read and write to that format, you lose quality.
The images are pixel art, so they have a set number of pixels and a set color pallet. By not changing quality I mean that by doubling the dimensions, what was originally 1 pixel becomes a 2x2 pixels, without a change in color.

For example, from this:
Image
to this:
Image

Re: How to double the dimensions of images as long as they don't go above 192X192?

Posted: 2020-03-02T16:40:47-07:00
by fmw42
ImageMagick can do that by using -scale 200% or -sample 200%. Or you can use pixel art scaling with -magnify with a number of different scaling approaches. See https://imagemagick.org/script/command- ... hp#magnify.

You can process a whole folder of images in one command using mogrify. See https://imagemagick.org/Usage/basics/#mogrify

On IM 7 use magick mogrify. On IM 6 use mogrify.

Re: How to double the dimensions of images as long as they don't go above 192X192?

Posted: 2020-03-02T20:37:35-07:00
by GeeMack
tommaniacal wrote:
2020-03-02T13:25:13-07:00
My question is, is there a way to double the size of all images less than or equal to 96X96, so that all of the images are less than or equal to 192X192 afterwards?
Re-scaling can be done with pretty basic ImageMagick commands. You should be able to use a "for" loop in a script to run an IM command on entire directories of images.

To conditionally re-scale a single image with IM version 7 is a pretty simple matter. A command like this will scale the input image by 200% only if it's 96 pixels or less.

Code: Select all

magick input.png -write mpr:map -scale "%[fx:s.w>96?100:200]%" -remap mpr:map result7.png
Note that command writes the input image to a temporary memory register, then uses it again to remap the scaled image to the original colors. That should assure the pallet matches.

The same thing can be done in a single command using IM version 6, but it's more complicated. This command is an example...

Code: Select all

convert input.png -write mpr:map -filter box -scale 200% \
   +distort SRT "0,0 %[fx:s.w>192?0.5:1] 0" -shave 1 -remap mpr:map result6.png
Scaling up with "+distort" seems to introduce some unwanted extra information, so that command starts by scaling the input up 200%, then scales down the ones that exceed the size condition. That and the "-remap" seems to keep it faithful to the original input colors.

Re: How to double the dimensions of images as long as they don't go above 192X192?

Posted: 2020-03-02T22:51:40-07:00
by tommaniacal
GeeMack wrote:
2020-03-02T20:37:35-07:00
tommaniacal wrote:
2020-03-02T13:25:13-07:00
My question is, is there a way to double the size of all images less than or equal to 96X96, so that all of the images are less than or equal to 192X192 afterwards?
Re-scaling can be done with pretty basic ImageMagick commands. You should be able to use a "for" loop in a script to run an IM command on entire directories of images.

To conditionally re-scale a single image with IM version 7 is a pretty simple matter. A command like this will scale the input image by 200% only if it's 96 pixels or less.

Code: Select all

magick input.png -write mpr:map -scale "%[fx:s.w>96?100:200]%" -remap mpr:map result7.png
Note that command writes the input image to a temporary memory register, then uses it again to remap the scaled image to the original colors. That should assure the pallet matches.

The same thing can be done in a single command using IM version 6, but it's more complicated. This command is an example...

Code: Select all

convert input.png -write mpr:map -filter box -scale 200% \
   +distort SRT "0,0 %[fx:s.w>192?0.5:1] 0" -shave 1 -remap mpr:map result6.png
Scaling up with "+distort" seems to introduce some unwanted extra information, so that command starts by scaling the input up 200%, then scales down the ones that exceed the size condition. That and the "-remap" seems to keep it faithful to the original input colors.
Thank you very much for the response! This may be a stupid question because I'm new to ImageMagick, but would I put that script into the windows command prompt? If I do that after opening the folder through the command prompt it says "unable to open 'input.png', no such file or directory

I'm using IM v. 7

Re: How to double the dimensions of images as long as they don't go above 192X192?

Posted: 2020-03-02T23:04:56-07:00
by fmw42
You need to launch your script from the directory where you have your images. Or include the path to the image.

However, I think you might be better off using mogrify as it will process a whole folder of file. No scripting is needed.

Create a new directory to hold your output images.
The change directory to where you have your input images
The at your CMD window type:

Code: Select all

mogrify -path path_to/output_directory -format png -scale 200% *.png
fill in your path to your output directory and the name of the directory in the above

If using IM 7, then change mogrify to magick mogrify.

Note that when using a .bat script on windows, you need to escape the % as %% in GeeMack's command.

Re: How to double the dimensions of images as long as they don't go above 192X192?

Posted: 2020-03-03T14:06:36-07:00
by tommaniacal
fmw42 wrote:
2020-03-02T23:04:56-07:00
You need to launch your script from the directory where you have your images. Or include the path to the image.

However, I think you might be better off using mogrify as it will process a whole folder of file. No scripting is needed.

Create a new directory to hold your output images.
The change directory to where you have your input images
The at your CMD window type:

Code: Select all

mogrify -path path_to/output_directory -format png -scale 200% *.png
fill in your path to your output directory and the name of the directory in the above

If using IM 7, then change mogrify to magick mogrify.

Note that when using a .bat script on windows, you need to escape the % as %% in GeeMack's command.
Thank you! Is there a way to do this only for images that are 96x96 pixels or smaller?