Border with and font size in percent

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Nops
Posts: 6
Joined: 2013-05-01T12:38:10-07:00
Authentication code: 6789

Border with and font size in percent

Post 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
Nops
Posts: 6
Joined: 2013-05-01T12:38:10-07:00
Authentication code: 6789

Re: Border with and font size in percent

Post by Nops »

Sorry, i forget.

I use Windows 7 and ImageMagick 6.8.5-3 2013-04-27 Q16

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Border with and font size in percent

Post 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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Border with and font size in percent

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Border with and font size in percent

Post 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:

Code: Select all

set Width=123
set Height=456
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Border with and font size in percent

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Nops
Posts: 6
Joined: 2013-05-01T12:38:10-07:00
Authentication code: 6789

Re: Border with and font size in percent

Post 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 8) - Also for watermarks with pictures have different resolution.

I try the method with the formulars. ((x/100)*percent) should do it.
Nops
Posts: 6
Joined: 2013-05-01T12:38:10-07:00
Authentication code: 6789

Re: Border with and font size in percent

Post 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 :)
Nops
Posts: 6
Joined: 2013-05-01T12:38:10-07:00
Authentication code: 6789

Re: Border with and font size in percent

Post by Nops »

...South -font "AR-BERKLEY" -pointsize %fsize% ...

(Without the Backspace)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Border with and font size in percent

Post 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
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Border with and font size in percent

Post 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 8) - 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Nops
Posts: 6
Joined: 2013-05-01T12:38:10-07:00
Authentication code: 6789

Re: Border with and font size in percent

Post 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 "-" ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Border with and font size in percent

Post 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.
Post Reply