Mogrify doesnt work in .bat-file. What to do?

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?".
MomentumHunt91
Posts: 26
Joined: 2015-08-03T14:15:55-07:00
Authentication code: 1151

Mogrify doesnt work in .bat-file. What to do?

Post by MomentumHunt91 »

mkdir SDtemp
copy *@2x*.png SDtemp
mogrify -format png -resize 50%% SDtemp/*@2x*.png {-> This Step doesn´t work!}
pushd SDtemp

setlocal enableDelayedExpansion
for %%a in (*.png) do (
set "filename=%%~nxa"
set "purged_filename=!filename:@2x=!"
ren %%~nxa !purged_filename!
)
endlocal


The program should do:

1. Create in the same folder a folder called "SDtemp".
2. Copy all "@2x" out of it into SDtemp. (Example: example@2x.png)
3. Change all names without @2x. (Example: exmaple@2x.png -> example.png)
4. Resize all png´s to 50%-

Step 1 works. Step 2 works. Step 3 works. Step 4 doesn´t!

So does it looks like;
http://img5.fotos-hochladen.net/uploads ... fuhxmo.png
.bat-file Download:
http://www.mediafire.com/download/c50cv ... HDtoSD.bat


I know that it works with cmd.exe. But i never used it...
Can u help me to create an cmd.exe file for this? Or is their another way with .bat?

PS: You can send me a private message too. (I also got Skype/TS)

Much Thanks
MomentumHunt91
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Mogrify doesnt work in .bat-file. What to do?

Post by snibgo »

This Step doesn´t work!
What happens? Do you get an error message? What happens if you put "-verbose" at the first command to mogrify?
snibgo's IM pages: im.snibgo.com
MomentumHunt91
Posts: 26
Joined: 2015-08-03T14:15:55-07:00
Authentication code: 1151

Re: Mogrify doesnt work in .bat-file. What to do?

Post by MomentumHunt91 »

x
Last edited by MomentumHunt91 on 2015-08-03T16:10:19-07:00, edited 1 time in total.
MomentumHunt91
Posts: 26
Joined: 2015-08-03T14:15:55-07:00
Authentication code: 1151

Re: Mogrify doesnt work in .bat-file. What to do?

Post by MomentumHunt91 »

Like in the .png i linked.
I don´t get an error message. It got the size 136x136 before and after i use this...
MomentumHunt91 wrote:What happens if you put "-verbose" at the first command to mogrify?
-> Never did that. Can u code it? So i will try it.
mogrify -verbose -format png -resize 50%% SDtemp/*@2x*.png
That didn´t work...
ceepea
Posts: 9
Joined: 2015-07-31T09:33:52-07:00
Authentication code: 1151

Re: Mogrify doesnt work in .bat-file. What to do?

Post by ceepea »

I do not see an error message in the linked png.
Seems to me that you would want to do the mogrify after the renaming , not before.
wonder if the characters "/@" is causing trouble. Think you meant "\@" .
does "@" require escaping when using Windows?
MomentumHunt91
Posts: 26
Joined: 2015-08-03T14:15:55-07:00
Authentication code: 1151

Re: Mogrify doesnt work in .bat-file. What to do?

Post by MomentumHunt91 »

ceepea wrote:I do not see an error message in the linked png.
There isn´t an error message. It just doesn´t scale the picture to the right size the rest works.
You can test it too. Linked a downloadlink in down on my main post. Just get a folder with a png called XXX@2x.png.
ceepea wrote:Seems to me that you would want to do the mogrify after the renaming , not before.
I actually don´t look up on the order. I just wish it works. :p
ceepea wrote:wonder if the characters "/@" is causing trouble. Think you meant "\@" .
Tried out with "\@" doesn´t work neither...
ceepea wrote:does "@" require escaping when using Windows?
It doesn´t.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Mogrify doesnt work in .bat-file. What to do?

Post by fmw42 »

In IM @ is a special character that indicates a file to be used, such as @file.txt. I do not think @ works in mogrify, only convert. Do you mean to use it as a wild card in some way? If so, then use *. In a batch file, to escape some character you need to use ^ rather than \. So ^@, if the @ is a character in your image names. But I do not think mogify can have that kind of wild card usage to specify some directory. I think you need to cd to the directory your images are in. Then use the -path option to mogrify to specify the output directory. Then use just * at the end. You may be able to use *@2x*.png. I am not sure of that, but I am pretty sure you cannot have a directory specified that way. You need to use -path for the output directory.

Sorry I am not a windows user, so do not know windows wildcards and escapes that well.
MomentumHunt91
Posts: 26
Joined: 2015-08-03T14:15:55-07:00
Authentication code: 1151

Re: Mogrify doesnt work in .bat-file. What to do?

Post by MomentumHunt91 »

In IM @ is a special character that indicates a file to be used, such as @file.txt.
Ye it´s an @txt.file.
I do not think @ works in mogrify, only convert. Do you mean to use it as a wild card in some way? If so, then use *. In a batch file, to escape some character you need to use ^ rather than \. So ^@, if the @ is a character in your image names. But I do not think mogify can have that kind of wild card usage to specify some directory.

I don´t know much about a batch file.... It would be awesome if u can help to create this little file with me...
I think you need to cd to the directory your images are in. Then use the -path option to mogrify to specify the output directory. Then use just * at the end. You may be able to use *@2x*.png. I am not sure of that, but I am pretty sure you cannot have a directory specified that way. You need to use -path for the output directory.
This actually isn´t possible. I want to reupload it on my "userpage" after. And it´ll be a free upload for the game "osu". So it need to work for any downloader. Specificaly cd /path" won´t work for me.


The game "osu" got always a "skin"-folder u can change. I want to create this file to automaticaly create an SD folder that close the half work for all.
It got the normal .png´s (SD) and the "@2x" .png´s (HD). The program should search all the "@2x" files and create a new folder where u find all "SD"-files [-50% size].
Here is a picture about it:
http://img5.fotos-hochladen.net/uploads ... 8n2v3k.png
ceepea
Posts: 9
Joined: 2015-07-31T09:33:52-07:00
Authentication code: 1151

Re: Mogrify doesnt work in .bat-file. What to do?

Post by ceepea »

what happens when you try the setup with files that do not "@" or any other non-alphanumeric characters?
MomentumHunt91
Posts: 26
Joined: 2015-08-03T14:15:55-07:00
Authentication code: 1151

Re: Mogrify doesnt work in .bat-file. What to do?

Post by MomentumHunt91 »

ceepea wrote:what happens when you try the setup with files that do not "@" or any other non-alphanumeric characters?
I try it out and edit this soon gimme a second.

EDIT: Tried it out now. It does the same thing. Copy all from the Input-folder right to the Output-folder. Change all the names to the right way. But it still doesnt change the sitz to -50%....
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Mogrify doesnt work in .bat-file. What to do?

Post by fmw42 »

You cannot use an @textfile.txt in mogrify. That only works with convert. Moreover, there is no input in mogrify, only the * for the output. Convert allows @textfile.txt for input, but not output. Furthermore, IM does not create new directories. They have to be created first before referencing them in command. So you will need to make your batch file script use OS commands to create directories and change directories. There are windows equivalents to cd, if it does not allow that. You will need to use -path to specify the existing output directory in mogrify.

Sorry I am not a Windows user and know relatively nothing about scripting on Windows.
MomentumHunt91
Posts: 26
Joined: 2015-08-03T14:15:55-07:00
Authentication code: 1151

Re: Mogrify doesnt work in .bat-file. What to do?

Post by MomentumHunt91 »

fmw42 wrote:You cannot use an @textfile.txt in mogrify. That only works with convert. Moreover, there is no input in mogrify, only the * for the output. Convert allows @textfile.txt for input, but not output.
Good to know. And thanks for that. So i will keep going and say that i want to convert all data´s to the input folder with the right size. And yes i just used the mogrify for the Output.

But i actually tried that and don´t know how that really works. I watches some guides for the right command but I always did something wrong. Can u help me with this?
Last edited by MomentumHunt91 on 2015-08-03T18:18:16-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Mogrify doesnt work in .bat-file. What to do?

Post by fmw42 »

Please read about batch scripting by searching google or from http://www.imagemagick.org/Usage/windows/
MomentumHunt91
Posts: 26
Joined: 2015-08-03T14:15:55-07:00
Authentication code: 1151

Re: Mogrify doesnt work in .bat-file. What to do?

Post by MomentumHunt91 »

fmw42 wrote:Please read about batch scripting by searching google or from http://www.imagemagick.org/Usage/windows/
I actually just need 1 command now:
To convert all "xxx.2x" data´s to xxx data´s with the right size. (The folder can be the Input folder it´s fine.)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Mogrify doesnt work in .bat-file. What to do?

Post by fmw42 »

MomentumHunt91 wrote:
fmw42 wrote:You cannot use an @textfile.txt in mogrify. That only works with convert. Moreover, there is no input in mogrify, only the * for the output. Convert allows @textfile.txt for input, but not output.
Good to know. And thanks for that. So i will keep going and say that i want to convert all data´s to the input folder with the right size. And yes i just used the mogrify for the Output.

But i actually tried that and don´t know how that really works. I watches some guides for the right command but I always did something wrong. Can u help me with this?
Typical procedure is:

create output directory, if it does not exist.
cd to input directory

Code: Select all

mogrify -format png -path full_path_to/output_directory -resize WxH *
That will process every every file (png, jpg, tiff, etc) in the input directory, resize it, and put the same named file with the suffix .png in the output directory.

If you just want to process input png files, then use

Code: Select all

mogrify -format png -path full_path_to/output_directory -resize WxH *.png
Post Reply