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
Naming a file
Re: Naming a file
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.
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 !
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"
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
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
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
This example gets the date and time using IM and uses it to watermark the image:
Let me know if you get it sorted and I will add it to my examples.
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
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
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Naming a file
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.
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
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
Nick