Page 1 of 1
Naming a file
Posted: 2009-07-31T00:57:53-07:00
by oldNick
My aim is the resize a file, converting it from a given format to jpg. I then wish to keep the filename, but with a time stamp in the filename, when I save the file.
I want to do this by dragging and dropping the source file onto the command line icon.
At this stage, before I start playing with enhancements, my command line (batch file) code is
convert %1 -resize 800x800 -quality 90 c:\outputdir\filename.jpg
(use the convert.exe to convert the dropped filename (%1) to c:\outputdir as a jpeg.)
At present this works, but the file is always called "filename.jpg". I am wanting to make that into the original name of the source file, dated and timed.
Any help appreciated, even if it's a pointer to where to read. I have looked through quite a bit of the documentation.
Nick
Re: Naming a file
Posted: 2009-07-31T03:03:35-07:00
by Bonzo
Here are some batch files I tried out earlier this year:
http://www.rubblewebs.co.uk/imagemagick/batch.php
I have created a batch file on my desktop which I just drop files into and it resizes them and adds a border.
Code: Select all
:: Drag and drop resizing - saves the modified image back in the original directory
:: Adds the th_ to the front of the image name
convert.exe %1 -thumbnail 640x640 -bordercolor Black -border 2x2 -unsharp 1.5x1+0.7+0.02 -quality 80 "th_%~n1.jpg"
You will need to get the date and time from somewhere and add it to the filename.
I hope this gives you some pointers; it was a while ago that I did it and as I do not usualy work with batch files ( and due to my age ) I can not remember the full workings of batch files !
Re: Naming a file
Posted: 2009-07-31T03:38:34-07:00
by oldNick
Excellent! Thank you. That ~n did the trick.
The date and time I can probably suss out. I was not sure if IM itself provided such stuff, or I had to use DOS.
Nick
Re: Naming a file
Posted: 2009-07-31T04:33:27-07:00
by Bonzo
This example gets the date and time using IM and uses it to watermark the image:
Code: Select all
:: Use the ImageMagick identify command to set the variable DateTime to equal the Date and Time from the photo EXIF data
FOR /F %%x IN ('identify -format "%%[EXIF:DateTime]" %INPUTFILE%') DO SET DateTime=%%x
:: Add the date the photo was taken to the image
convert %1 -pointsize 20 -fill black -gravity northwest ^
-annotate +0+0 "Date: %DateTime%" "%~p1date_%~n1.jpg"
Let me know if you get it sorted and I will add it to my examples.
Re: Naming a file
Posted: 2009-07-31T12:09:57-07:00
by oldNick
Thanks for that and it may be useful and is certainly good to know, because I can see that there is a lot of file info that can be done with IM.
I am only scratching the surface from what I have started to read.
But at present I am after the system date and time, as there may be multiple copies of the same file, perhaps with alterations made to the source. The EXIF time would be the same for each one.
Nick
Re: Naming a file
Posted: 2009-07-31T14:52:47-07:00
by fmw42
I don't believe that IM will provide system information such as date and time. On unix:
date
Fri Jul 31 14:50:03 PDT 2009
so you could put that in a string variable and parse it or just pipe to sed or something else to parse what you need
date_time=`date`
echo $date_time
Fri Jul 31 14:52:00 PDT 2009
I am sure that PHP can access the date and time with its own calls, if you are using PHP. Likewise Windows also must have some such ability.
Re: Naming a file
Posted: 2009-07-31T15:06:42-07:00
by oldNick
Ok. Thanks for that. Some of these command line apps will have a date/time output. I can grab it from DOS but it's messier.
Nick