Page 1 of 1
Odd, thrown error.
Posted: 2019-06-19T21:47:01-07:00
by Asellia
I am unsure if this is a bug, or just me having no idea what I'm doing-- I've been hammering at this for a bit with basically no knowledge on the system. Basically, I'm attempting to resize (on windows 10) all jpg files in a directory to the nearest power of 2 dimensions (lower, not higher). It, however, is throwing me some errors. I notice in said errors it shows the power of two dimensions, though-- so I hope I'm close. I'm rather horrid at coding, and I sort of patchworked a lot of different code I found through google- this seemed like it's pretty close, thus why I'm asking.
Code: Select all
FOR %a in (D:\Mods\Images\*.jpg) DO D:\Applications\ImageMagick\magick.exe %a -resize ${"%[fx:2^(ceil(log(w)/log(2)))/2]"}x${"%[fx:2^(ceil(log(h)/log(2)))/2]"} D:\Mods\Images2\%a
I am pasting this into command prompt, basically.
The errors are all along the lines of:
Code: Select all
C:\WINDOWS\system32>D:\Applications\ImageMagick\magick.exe D:\Mods\Images\httpiimgurcomztwkBXfjpg.jpg -resize ${"%[fx:2^(ceil(log(w)/log(2)))/2]"}x${"%[fx:2^(ceil(log(h)/log(2)))/2]"} D:\Mods\Images2\D:\Mods\Images\httpiimgurcomztwkBXfjpg.jpg
magick.exe: invalid argument for option '-resize' '${2048}x${1024}' at CLI arg 2 @ error/operation.c/CLISimpleOperatorImage/3170.
Re: Odd, thrown error.
Posted: 2019-06-19T21:56:05-07:00
by fmw42
Try removing the ${ and the ending }. I do not think that is correct either for Windows or Unix. Sorry, I am not a Windows user.
Code: Select all
FOR %a in (D:\Mods\Images\*.jpg) DO D:\Applications\ImageMagick\magick.exe %a -resize "%[fx:2^(ceil(log(w)/log(2)))/2]"x"%[fx:2^(ceil(log(h)/log(2)))/2]" D:\Mods\Images2\%a
Does that work. Also if this is in a .bat script, then % needs to be doubled. Also ^ in Windows is an escape and would need to be doubled.
But if this does not work, wait for a Windows user to help and correct my comments.
Re: Odd, thrown error.
Posted: 2019-06-19T22:04:51-07:00
by Asellia
Sadly, no good- thank you though for trying to help, though. I wasn't too sure what to expect given I basically frankenstein'd this together, and hoped it worked. I'm not the best when it comes to this sort of thing, sort of just glad I've got it this far.
Edit: Using that code, in case anyone needs to know, it turns into:
Code: Select all
Invalid argument @ error/blob.c/OpenBlob/3497.
Re: Odd, thrown error.
Posted: 2019-06-20T05:11:44-07:00
by snibgo
Removing ${ and } makes it work for me, in Windows 8.1.
The output filename isn't good. A typical value for %a is "D:\Mods\Images\abcd.jpg", so the output filename would be "D:\Mods\Images2\D:\Mods\Images\abcd.jpg".
Re: Odd, thrown error.
Posted: 2019-06-20T08:21:50-07:00
by Asellia
Thanks, that seems.. close. Replacing it with just %a seems to not resize anything, though. Is it because it's the same output file name, now? Is there a way to output it into a new folder, with the same filename? All I know is atm it goes through all the files, and proceeds to resize nothing despite themn ot being power of two. If I replace resize with -format, and use info:, it outputs what it SHOULD turn into, however.
Edit: I could be mistaken, but it may be resizing them, but the dimensions when I highlight the files with my cursor is still the old dimensions.
Edit 2: It appears the images just halved their width/height, and did not goto the next power of 2 lower. Is my math just bad? Or do I need to make it ignore aspect ratio?
Re: Odd, thrown error.
Posted: 2019-06-20T08:43:19-07:00
by snibgo
For the output filename, you might use "D:\Mods\Images2\%~nxa". This takes the name and extension from %a, with a new drive and path.
On resizing, I don't know what you want. If the input is 400x200, what should the output be? Likewise 512x512? etc.
Re: Odd, thrown error.
Posted: 2019-06-20T08:43:35-07:00
by fmw42
It seems to work except if the image is already a power of 2, then it goes down one level of 2.
Code: Select all
dim=10
convert xc: -format "%[fx:2^(ceil(log($dim)/log(2)))/2]" info:
8
Code: Select all
dim=8
convert xc: -format "%[fx:2^(ceil(log($dim)/log(2)))/2]" info:
4
So perhaps you need to test first if already a power of 2.
Re: Odd, thrown error.
Posted: 2019-06-20T10:58:46-07:00
by Asellia
I got it working, yeah-- I ended up simply scaling them all up, rather than down -- to insure readability. Some filesizes went up, but thats not an issue, and its all legible/working after a lot of fiddling with contrast/gamma, and some filters. Thank you so much for the help!