Page 1 of 1

Get image01 dimensions and use same to resize other images

Posted: 2016-10-08T02:14:44-07:00
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
  )
)

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

Posted: 2016-10-08T06:22:28-07:00
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.

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

Posted: 2016-10-10T05:43:42-07:00
by samraj
What would be the right appraoch to fix this. I am still working on batch scripting basics. kindly help