Optimization of Code
Posted: 2008-06-10T04:16:37-07:00
I have got a large number of images which I need to resize and put a text box under the new resized image containing some text.
My code works fine but I can't help thinking that it is quite inefficient. I have only just started using Imagemagick and it seems to be a highly efficient tool if used correctly. 5 lines of code seems quite a lot for what seems to be a relatively easy task.
It would be great to know if there is a better way of doing this.
Thanks a lot,
Sean
REM ** CREATE IMAGE **
rem resize image so that 150px is longest dimension
convert -resize 150x150 c01t01v0010.bmp output1.jpg
rem place on 150x150 white background (imagetemplate.jpg)
composite -gravity center output1.jpg template\imagetemplate.jpg output2.jpg
REM ** CREATE TEXT **
rem Put text onto white background 150px wide, height variable
convert -gravity center -font Arial -pointsize 12 -size 150x caption:"This is my text" output3.jpg
rem Place image on 150x20 image (texttemplate.jpg)
composite -gravity center output3.jpg template\texttemplate.jpg output4.jpg
REM ** ADD TOGETHER **
convert output2.jpg output4.jpg -append -trim final.jpg
My code works fine but I can't help thinking that it is quite inefficient. I have only just started using Imagemagick and it seems to be a highly efficient tool if used correctly. 5 lines of code seems quite a lot for what seems to be a relatively easy task.
It would be great to know if there is a better way of doing this.
Thanks a lot,
Sean
REM ** CREATE IMAGE **
rem resize image so that 150px is longest dimension
convert -resize 150x150 c01t01v0010.bmp output1.jpg
rem place on 150x150 white background (imagetemplate.jpg)
composite -gravity center output1.jpg template\imagetemplate.jpg output2.jpg
REM ** CREATE TEXT **
rem Put text onto white background 150px wide, height variable
convert -gravity center -font Arial -pointsize 12 -size 150x caption:"This is my text" output3.jpg
rem Place image on 150x20 image (texttemplate.jpg)
composite -gravity center output3.jpg template\texttemplate.jpg output4.jpg
REM ** ADD TOGETHER **
convert output2.jpg output4.jpg -append -trim final.jpg