How to use conditions with ImageMagick properly

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
imanasya
Posts: 36
Joined: 2018-10-05T11:21:07-07:00
Authentication code: 1152

How to use conditions with ImageMagick properly

Post by imanasya »

When 0.jpg and 1.jpg have resolution 356x800 (w1<h1) and 596x770 (w2<h2) respectively, this line:

Code: Select all

magick 0.jpg fuzz 2%% -trim +repage -quality 100 first.jpg
still doesn't work and every time gives me combined image. Help me please find the mistake in the code:

Code: Select all

@echo off&setlocal enabledelayedexpansion

for /f "tokens=1,2 delims=:" %%x in ('convert 0.jpg -fuzz 2%% -trim +repage -format %%w:%%h +write info: NULL') do set a/ w1=%%x&set a/ h1=%%y
for /f "tokens=1,2 delims=:" %%x in ('convert 1.jpg -fuzz 2%% -trim +repage -format %%w:%%h +write info: NULL') do set a/ w2=%%x&set a/ h2=%%y

if !w1! LSS !h1! (
  if !w2! LSS !h2! (
  magick 0.jpg fuzz 2%% -trim +repage -quality 100 first.jpg
  ) else (
  magick 0.jpg 1.jpg -set option:dim "%%[fx:max(max(u.w,v.w),max(u.h,v.h))]" -filter Catrom -resize "%%[dim]x%%[dim]" -unsharp 0x1+0.8+0.05 -background white -gravity center -append -quality 100 combined.jpg
  )
) else (
magick 0.jpg 1.jpg -set option:dim "%%[fx:max(max(u.w,v.w),max(u.h,v.h))]" -filter Catrom -resize "%%[dim]x%%[dim]" -unsharp 0x1+0.8+0.05 -background white -gravity center -append -quality 100 combined.jpg
)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to use conditions with ImageMagick properly

Post by snibgo »

For "set", type "help set". That shows the syntax is "set /a", not "set a/".

I suggest you use "magick" for v7, not "convert".
snibgo's IM pages: im.snibgo.com
imanasya
Posts: 36
Joined: 2018-10-05T11:21:07-07:00
Authentication code: 1152

Re: How to use conditions with ImageMagick properly

Post by imanasya »

It did not help. I'm getting the error:

Code: Select all

magick: unable to open image 'fuzz': No such file or directory @ error/blob.c/OpenBlob/3489.
magick: no decode delegate for this image format `' @ error/constitute.c/ReadImage/556.

Code: Select all

@echo off&setlocal enabledelayedexpansion

for /f "tokens=1,2 delims=:" %%x in ('magick 0.jpg -fuzz 2%% -trim +repage -format %%w:%%h +write info: NULL') do set /a w1=%%x&set /a h1=%%y
for /f "tokens=1,2 delims=:" %%x in ('magick 1.jpg -fuzz 2%% -trim +repage -format %%w:%%h +write info: NULL') do set /a w2=%%x&set /a h2=%%y

if !w1! LSS !h1! (
  if !w2! LSS !h2! (
  magick 0.jpg fuzz 2%% -trim +repage -quality 100 first.jpg
  ) else (
  magick 0.jpg 1.jpg -set option:dim "%%[fx:max(max(u.w,v.w),max(u.h,v.h))]" -filter Catrom -resize "%%[dim]x%%[dim]" -unsharp 0x1+0.8+0.05 -background white -gravity center -append -quality 100 combined.jpg
  )
) else (
magick 0.jpg 1.jpg -set option:dim "%%[fx:max(max(u.w,v.w),max(u.h,v.h))]" -filter Catrom -resize "%%[dim]x%%[dim]" -unsharp 0x1+0.8+0.05 -background white -gravity center -append -quality 100 combined.jpg
)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to use conditions with ImageMagick properly

Post by snibgo »

Options always start with a "+" or "-". You had neither, so IM assumed "trim" was an image you wanted to read.
snibgo's IM pages: im.snibgo.com
imanasya
Posts: 36
Joined: 2018-10-05T11:21:07-07:00
Authentication code: 1152

Re: How to use conditions with ImageMagick properly

Post by imanasya »

Thank you very much. I forgot minus.
Post Reply