Page 1 of 1
Border with and font size in percent
Posted: 2013-05-01T13:28:19-07:00
by Nops
Hello,
I have a problem. I created a little script to make a frame to my pictures and a label.
Code: Select all
@echo off
@echo Beschriftungstext:
set /p beschr=
set neu=%1
set alle=%*
FOR %%a IN (%alle%) DO convert -bordercolor white -border 1 -bordercolor black -border 25%x25% -gravity South -font "AR-BERKLEY" -pointsize 22 -fill white -draw "text 0,0 '%beschr%'" %%a %%a
pause
(This is a batch in the send-to folder for right-click the image and frame and label it)
This works. But what i want is to set the border width in percent. Some pictures are bigger, some smaller. So the frame ist thin or thick, depents on the picture resolution.
To solve this, i have to set border in percent (here i tried with 25%x25%) but it doesn´t work.
Also i have to set the font size in percent.
I readed the manual, forums, but i cant find a solution.
Sombody´s got an idea to do this?
Thanks a lot
Re: Border with and font size in percent
Posted: 2013-05-01T13:31:40-07:00
by Nops
Sorry, i forget.
I use Windows 7 and ImageMagick 6.8.5-3 2013-04-27 Q16
Thanks
Re: Border with and font size in percent
Posted: 2013-05-01T13:33:26-07:00
by fmw42
To my knowledge, IM does not support pointsize in percent nor border size in percent. You will have to convert percent to actual pixels given the image dimensions. My understanding is that font size in points is the same as pixels. But I may be wrong about that. So if some one knows otherwise, I will defer to them.
Re: Border with and font size in percent
Posted: 2013-05-01T14:06:30-07:00
by Bonzo
I have had a play with batch scripts but do not fully understand them. Here are couple of line of code that may be helpful to get the image dimensions into variables:
Code: Select all
:: Set the variable width to the image width
For /F %%# in ('identify -verbose -ping -format "%%[fx:w]" "%1"') Do (SET /A "width=%%#")
:: Set the variable height to the image height
For /F %%# in ('identify -verbose -ping -format "%%[fx:h]" "%1"') Do (SET /A "height=%%#")
To be honist I can not remember what the /F %%# means now but I was working on a directory of images - old age I think
You can then use this in your code to work out the pixel value of the border. You can find the full code this was taken from at the bottom of this page:
Batch script examples
Re: Border with and font size in percent
Posted: 2013-05-01T14:23:06-07:00
by snibgo
Width and height in one crafty move:
Code: Select all
FOR /F %%L IN ('identify -format "Width=%%w\nHeight=%%h" %1') DO set %%L
This results in the execution of two "set" commands, eg:
Re: Border with and font size in percent
Posted: 2013-05-01T22:31:25-07:00
by anthony
That is a nice method...
A good one to add to the windows DOS API section.
Added IM Examples, Windows Usage, Set Multiple Values from a Single Command
http://www.imagemagick.org/Usage/windows/#multiple
I have done similar things with shell, though it has to be done at a similar level of complexity when it is more than one variable.
More typicaly for shell I get one value (string) of all items and then process that to split up the results.
Warning. do not do this for free-form strings which you can not be sure of the strings contents. For example extracting a image comment from an image some user submitted to a web page. Such a string could have quotes or other things that may allway a cracker to break through your script security.
In the above example it is fine, as you can be sure you are only getting a valid number.
Re: Border with and font size in percent
Posted: 2013-05-02T10:01:07-07:00
by Nops
Hello
Thanks a lot for your response.
Imagemagick cannot do this job itself? Hmm the programmers should add this, i think this feature most people wo work with pictures with different Resolutions
- Also for watermarks with pictures have different resolution.
I try the method with the formulars. ((x/100)*percent) should do it.
Re: Border with and font size in percent
Posted: 2013-05-02T11:01:28-07:00
by Nops
This one works:
Code: Select all
@echo off
@echo Beschriftungstext:
set /p beschr=
FOR /F %%i IN ('identify -format "%%[fx:min(w,h)*0.05]" %1') DO SET psize=%%i
FOR /F %%j IN ('identify -format "%%[fx:min(w,h)*0.04]" %1') DO SET fsize=%%j
set neu=%1
set alle=%*
FOR %%a IN (%alle%) DO convert -bordercolor white -border 1 -bordercolor black -border %psize% -gravity South -font "AR-BERKLEY"
-pointsize %fsize% -fill white -draw "text -1,0 '%beschr%'" %%a %%a
pause
to the solution taked me this:
http://www.imagemagick.org/Usage/windows/#single
the section Using IM's FX Expressions
Thanks for your great helping
Re: Border with and font size in percent
Posted: 2013-05-02T11:03:10-07:00
by Nops
...South -font "AR-BERKLEY" -pointsize %fsize% ...
(Without the Backspace)
Re: Border with and font size in percent
Posted: 2013-05-02T12:16:50-07:00
by snibgo
You can do both calculations with a single identify:
Code: Select all
FOR /F "tokens=1,2" %%L IN ('identify -format "psize=%%[fx:min(w,h)*0.05]\nfsize=%%[fx:min(w,h)*0.04]" x.jpg') DO SET %%L
Re: Border with and font size in percent
Posted: 2013-05-02T17:44:49-07:00
by anthony
Nops wrote:Hello
Thanks a lot for your response.
Imagemagick cannot do this job itself? Hmm the programmers should add this, i think this feature most people wo work with pictures with different Resolutions
- Also for watermarks with pictures have different resolution.
I try the method with the formulars. ((x/100)*percent) should do it.
IM is leaning to do this... It is called... ImageMagick Version 7, and is where I have been spending my programming time.
Basically operators and asettings will have access percent escapes when processing there arguments (not for filenames). So you will be able to use value from images, or values you previously saved for later use.
It is however a lot of work, as there is a very large amount of code that needs to be checked through, updated, and debugged, as this feature is added.
ASIDE: Also being added is 'magick-script' which is basically 'command line options in files', using UNIX syntax.
With that you can just place the long command line option in a file and 'execute it'. What has not been added is things to allow you to feed 'arguments' to these scripts.
Re: Border with and font size in percent
Posted: 2013-05-04T09:56:09-07:00
by Nops
Imagemagick is great. I look forward for v7. Is the photoshop for dos xD
I work often with batch files and imagemagick is perfect for this. I know, a lot of programming time is in it, and its for free.
Thanks for this.
But another little question:
Can convert manipulate the output filename like this?
AR-3223-1233.jpg to AR32231233.jpg , delete the "-" ?
Re: Border with and font size in percent
Posted: 2013-05-04T10:03:18-07:00
by fmw42
Can convert manipulate the output filename like this?
AR-3223-1233.jpg to AR32231233.jpg , delete the "-" ?
I do not think IM 6 can do that, but your shell/dos should be able to do that easily. In unix it would be a separate step. You can change the string for the filename using sed or tr in unix and put that into a variable and then use the variable for the output name.