Get image01 dimensions and use same to resize other images

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
samraj
Posts: 2
Joined: 2016-10-08T01:06:05-07:00
Authentication code: 1151

Get image01 dimensions and use same to resize other images

Post by samraj »

I got a image01.jpg and some 50 images in folder Y with different dimensions. I want to convert and resize image01.jpg 50 images have each the dimensions obtained folder Y 50 images and have the output in folder z.

With little hands on Batch scripting and googling: the below script does 50 image output to folder z but size is same as image01.jpg. Kindly help.

Code: Select all

setlocal enabledelayedexpansion  
  %~d1
  CD "%~p1"
  MD small

 FOR %%f in (*.jpg) DO (
  set filename=%%f
    identify -format "%%w" %%f > w.txt
    set /p w=<w.txt
    identify -format "%%h" %%f > h.txt
    set /p h=<h.txt)
   FOR %%f in (*.jpg) DO (
    set filename=%%f
    convert imageA.jpg -resize %w%x%h%! small\%%~nxf
  )
)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Get image01 dimensions and use same to resize other images

Post by snibgo »

You have a loop within a loop, so you will execute the convert 50*50 = 2500 times. You use the same loop variable %%f, which is very bad news. You assign values to w and h within a loop but use the %w% and %h% form, so won't use the correct values. Instead, you should use the !w! and !h! forms.
snibgo's IM pages: im.snibgo.com
samraj
Posts: 2
Joined: 2016-10-08T01:06:05-07:00
Authentication code: 1151

Re: Get image01 dimensions and use same to resize other images

Post by samraj »

What would be the right appraoch to fix this. I am still working on batch scripting basics. kindly help
Post Reply