Page 1 of 1
make the size of the pictures the same as 1.png
Posted: 2019-02-05T14:29:34-07:00
by Nezar
Sorry for my English )
I have several jpg files
I need to make them the same size as the 1.png file.
I tried it
but I can't read the size of the picture 1.png in one line and pass it as a parameter ((
convert 1.png -set option:original '%wx%h' -delete 0 *.jpg -resize '%[original]' '%d'.png
Is it possible to solve this problem with just one line?
Thank!
Re: make the size of the pictures the same as 1.png
Posted: 2019-02-05T14:32:41-07:00
by fmw42
You can only do that one line with -set option in IM 7. With IM 6, you need to get the size as a variable in one line and then use another line to apply the variable to -resize.
Always best to provide your IM version and platform, when asking questions here.
With IM 7, this works fine for me for one image.
Code: Select all
magick lena.png -set option:dims "%wx%h" barn.jpg -delete 0 -resize "%[dims]" out.jpg
For two (or more images), this works fine:
Code: Select all
magick lena.png -set option:dims "%wx%h" barn.jpg monet2.jpg -delete 0 -resize "%[dims]" out_%d.jpg
Re: make the size of the pictures the same as 1.png
Posted: 2019-02-05T16:07:03-07:00
by GeeMack
Nezar wrote: ↑2019-02-05T14:29:34-07:00I have several jpg files
I need to make them the same size as the 1.png file.
Code: Select all
convert 1.png -set option:original '%wx%h' -delete 0 *.jpg -resize '%[original]' '%d'.png
Is it possible to solve this problem with just one line?
You can resize all the "*.jpg" images to match either the width or height of "1.png" while maintaining their original aspect using a command like this...
Code: Select all
convert *.jpg 1.png +distort SRT "%[fx:(u[-1].w-2)/s.w] 0" -delete -1 _ch%03d.png
That reads in all the source images "*.jpg", then reads in your reference image "1.png". It uses "+distort" to re-scale each ".jpg" to match the width of "1.png". The plus form of "+distort" scales the input so the viewport fits the scaled output, but normally it will add one pixel all the way around. The "-2" in the FX expression corrects that. The "-delete -1" removes the last image, which is the "1.png", before outputting the results.
To make the output images match the height of "1.png", change the w's in the FX expression to h's like this...
Code: Select all
convert *.jpg 1.png +distort SRT "%[fx:(u[-1].h-2)/s.h] 0" -delete -1 _ch%03d.png
As always, when reading multiple images into a single command, you may be limited by your available system memory.
Re: make the size of the pictures the same as 1.png
Posted: 2019-02-06T08:02:01-07:00
by Nezar
thank you very much!
happened!
Re: make the size of the pictures the same as 1.png
Posted: 2019-02-06T09:11:12-07:00
by Nezar
But can you somehow find out the name of the first file in the set * .jpg?
not to write 1.png manually, but to take it automatically.
Re: make the size of the pictures the same as 1.png
Posted: 2019-02-06T15:31:21-07:00
by GeeMack
Nezar wrote: ↑2019-02-06T09:11:12-07:00But can you somehow find out the name of the first file in the set * .jpg?
not to write 1.png manually, but to take it automatically.
I don't understand what you're trying to do. Maybe you can describe what you want step by step.
Re: make the size of the pictures the same as 1.png
Posted: 2019-02-06T17:50:11-07:00
by fmw42
I think what he wants is to get the name of the first image and use it with the output. But -set filename does not work with "%t", for which I think it should be allowed. So one cannot currently do that in one line. One would get the filename first with "%t" as a variable and then use it with your command to set the output filename.