make the size of the pictures the same as 1.png

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Nezar
Posts: 14
Joined: 2010-05-19T00:03:19-07:00
Authentication code: 8675308

make the size of the pictures the same as 1.png

Post by Nezar » 2019-02-05T14:29:34-07:00

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!

User avatar
fmw42
Posts: 24612
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: make the size of the pictures the same as 1.png

Post by fmw42 » 2019-02-05T14:32:41-07:00

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

User avatar
GeeMack
Posts: 672
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: make the size of the pictures the same as 1.png

Post by GeeMack » 2019-02-05T16:07:03-07:00

Nezar wrote:
2019-02-05T14:29:34-07:00
I 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.

Nezar
Posts: 14
Joined: 2010-05-19T00:03:19-07:00
Authentication code: 8675308

Re: make the size of the pictures the same as 1.png

Post by Nezar » 2019-02-06T08:02:01-07:00

thank you very much!
happened!

Nezar
Posts: 14
Joined: 2010-05-19T00:03:19-07:00
Authentication code: 8675308

Re: make the size of the pictures the same as 1.png

Post by Nezar » 2019-02-06T09:11:12-07:00

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.

User avatar
GeeMack
Posts: 672
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: make the size of the pictures the same as 1.png

Post by GeeMack » 2019-02-06T15:31:21-07:00

Nezar wrote:
2019-02-06T09:11:12-07:00
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.
I don't understand what you're trying to do. Maybe you can describe what you want step by step.

User avatar
fmw42
Posts: 24612
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: make the size of the pictures the same as 1.png

Post by fmw42 » 2019-02-06T17:50:11-07:00

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.

Post Reply