Page 1 of 1
Convert all png files in a subfolder, and then append filename and Extension name in the png at the bottom.
Posted: 2017-05-01T05:40:59-07:00
by cyberic68
Hi
I would like to convert all image in a subfolder with a windows batch file. Also then append the filename and the extension at the bottom of each image.
I have been using this code that work but for only one file at the time
FOR /F %%x IN ('convert %1 -ping -format "%%t" info:') DO SET name=%%x
FOR /F %%x IN ('convert %1 -ping -format "%%e" info:') DO SET ext=%%x
FOR /F %%x IN ('convert %1 -ping -format "%%w" info:') DO SET width=%%x
SET height=20
convert %1 ( -size %width%x%height% xc:white ) -append ^
( -background white -size x%height% -fill black label:%name% ) ^
-gravity southwest -compose over -composite ^
( -background white -size x%height% -fill black label:%ext% ) ^
-gravity southeast -compose over -composite ^
"%~n1.jpg"
Now I am trying with this one but it doesn't work
for %%f in (*._*) do ( convert %%~nf._* -ping -format "%%e" SET name=%%f -append -background white -size x%height% -fill black label:%name% -gravity southwest - compose over -composite %%~nf.jpg )
My files in my subfolder look like that, where the extension name has the date and time coded in it.
file_01._2015_05_01_1134
file_02._2015_05_01_1135
file_03._2015_05_01_1136
file_04._2015_05_01_1136
file_05._2015_05_01_1137
Thanks
Eric
Re: Convert all png files in a subfolder, and then append filename and Extension name in the png at the bottom.
Posted: 2017-05-01T07:40:44-07:00
by snibgo
Your files have names like "file_01._2015_05_01_1134". Are these images, like PNG or JPG etc, or something else? I strongly suggest you give them the usual extensions. Otherwise, most programs (and people) won't know what they are or how to process them. You can call them "file_01._2015_05_01_1134.png" etc.
When you have a series of command that work for a single image, you can wrap them in a "for ... in ... do (...) loop, to process all the commands for all the files.
Re: Convert all png files in a subfolder, and then append filename and Extension name in the png at the bottom.
Posted: 2017-05-01T07:44:33-07:00
by GeeMack
cyberic68 wrote: ↑2017-05-01T05:40:59-07:00I would like to convert all image in a subfolder with a windows batch file. Also then append the filename and the extension at the bottom of each image.
First, see if you can work with
snibgo's suggestion to use file extensions that are more meaningful. Also, it looks like there are a few problems with your code examples, so you might do better to start from scratch. Try this and let us know if it gets you close to what you want...
Code: Select all
mogrify -gravity south -splice 0x20 -pointsize 16 -annotate +0+8 "%[f]" -format jpg "*._*"
Then see what you need to tweak so it does exactly what you're trying to do.
Re: Convert all png files in a subfolder, and then append filename and Extension name in the png at the bottom.
Posted: 2017-05-01T10:31:19-07:00
by GeeMack
cyberic68 wrote: ↑2017-05-01T05:40:59-07:00I would like to convert all image in a subfolder with a windows batch file. Also then append the filename and the extension at the bottom of each image.
Here's another way to approach this which should produce a result very similar to the example you said works for single files...
Code: Select all
set HEIGHT=20
set /A POINTS=HEIGHT*8/10
mogrify -gravity southwest -splice 0x%HEIGHT% -pointsize %POINTS% ^
-annotate +1+1 "%[t]" -gravity southeast -annotate +1+1 "%[e]" -format jpg "*._*"
If you run it from a BAT script you'll need to double those percent signs on the "%[t]" and "%[e]" like "%%[t]" and "%%[e]".
Re: Convert all png files in a subfolder, and then append filename and Extension name in the png at the bottom.
Posted: 2017-05-01T12:37:45-07:00
by cyberic68
Hi GeeMack,
I have been successful with the two string that you have provided to me. I have added an extra % to be able to run it from a batch file
mogrify -gravity south -splice 0x20 -pointsize 16 -annotate +0+33 "%%[t]%%[e]" -format jpg "*._*"
My next challenge, it to make it run from a task scheduler. Now, it is only working when I double click on the batch file
Even If I have added the path of the mogrify.exe and the path of where my file are located
Code: Select all
"C:\Program Files\ImageMagick-7.0.5-Q16\"mogrify.exe -gravity south -splice 0x20 -pointsize 16 -annotate +0+33 "%%[t]%%[e]" -format jpg "R:\Private\overviews\bkp_ext\*._*"
Would you have an idea, how can I make it work ?
Also, I have tried to send those files to another drive & folder by using the -path option but it didn't work correctly. I have tried
Code: Select all
"C:\Program Files\ImageMagick-7.0.5-Q16\"mogrify.exe -gravity south -splice 0x20 -pointsize 16 -annotate +0+33 "%%[t]%%[e]" -format jpg "R:\Private\overviews\bkp_ext\*._*" -path Z:\Overviews\ *.jpg
Thanks
Eric
Re: Convert all png files in a subfolder, and then append filename and Extension name in the png at the bottom.
Posted: 2017-05-01T21:38:00-07:00
by GeeMack
cyberic68 wrote: ↑2017-05-01T12:37:45-07:00Even If I have added the path of the mogrify.exe and the path of where my file are located [...] Also, I have tried to send those files to another drive & folder by using the -path option...
You would usually have your script change to the directory that contains the images using the Windows command "pushd", then do the processing from there. Maybe try something like this...
Code: Select all
@echo off
set IMDIR="C:\Program Files\ImageMagick-7.0.5-Q16"
set WORKINGDIR="R:\Private\overviews\bkp_ext"
set OUTPUTDIR="Z:\Overviews"
pushd %WORKINGDIR%
%IMDIR%\mogrify.exe -gravity south -splice 0x20 -pointsize 16 ^
-annotate +0+33 "%%[t]%%[e]" -path %OUTPUTDIR% -format jpg "*._*"
Re: Convert all png files in a subfolder, and then append filename and Extension name in the png at the bottom.
Posted: 2017-05-02T09:16:47-07:00
by cyberic68
Hi
This works perfectly when I run it by double clicking on the batch file, but it give me this error message when I try to run it from my task scheduler (Marco Scheduler)
Here's the error message when it run via Marco Scheduler
C:\WINDOWS\system32>"C:\Program Files\ImageMagick-7.0.5-Q16\"mogrify.exe -gravit
y south -splice 0x20 -pointsize 16 -annotate +0+33 "%[t]%[e]" -format jpg "R:\Pr
ivate\overviews\bkp_ext\*._*"
mogrify.exe: unable to open image 'jpg:': Invalid argument @ error/blob.c/OpenBl
ob/3094.
mogrify.exe: unrecognized image format `jpg' @ error/mogrify.c/MogrifyImageComma
nd/4936.
Any Idea
Thanks
Eric
Re: Convert all png files in a subfolder, and then append filename and Extension name in the png at the bottom.
Posted: 2017-05-02T11:25:23-07:00
by cyberic68
Hi
Good news after rebooting my PC, I don't have the error anymore. this is working like a charm
Thanks !!!
Eric