How can you add vertical text in batch using the filename.

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?".
Robin55
Posts: 36
Joined: 2018-03-19T15:29:46-07:00
Authentication code: 1152

How can you add vertical text in batch using the filename.

Post by Robin55 »

Can anyone help me here?

I am using ImageMagick version 7.0.7-31

I need to alter this Batch file so the text appears vertical. I should mention the text is Japanese but I have that working

for %%F in (Front Covers\*.png) do magick "Front Covers\%%~nF.png" ( -background transparent -size 500x80 -font Arial-Unicode-MS -fill black -gravity west label:"%%~nF" -rotate 90 ) -gravity Southwest -geometry +80+55 -composite "Covers\%%~nF.png"

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

Re: How can you add vertical text in batch using the filename.

Post by fmw42 »

If you want to write ABC vertically, use "A\nB\nC" as your text string using new line \n between characters.

Robin55
Posts: 36
Joined: 2018-03-19T15:29:46-07:00
Authentication code: 1152

Re: How can you add vertical text in batch using the filename.

Post by Robin55 »

Thanks @fmw42 unfortunately I am not using English spelling and also all the files have a different names

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

Re: How can you add vertical text in batch using the filename.

Post by fmw42 »

I do not know of any other way other than placing new lines between characters. There is no built-in feature for vertical text that I know about.

See https://imagemagick.org/Usage/text/#label_vertical

Robin55
Posts: 36
Joined: 2018-03-19T15:29:46-07:00
Authentication code: 1152

Re: How can you add vertical text in batch using the filename.

Post by Robin55 »

@fmw42 would you be able to show me how I would write that command please?

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

Re: How can you add vertical text in batch using the filename.

Post by fmw42 »

Sorry, I do not use Windows. But in Unix,

Code: Select all

convert -background pink -pointsize 36 -fill black -gravity center label:"T\nE\nS\nT\nI\nN\nG" result.png
Image

Robin55
Posts: 36
Joined: 2018-03-19T15:29:46-07:00
Authentication code: 1152

Re: How can you add vertical text in batch using the filename.

Post by Robin55 »

That's no good to me I am afraid. I need to be able to use the file name not individual words....

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can you add vertical text in batch using the filename.

Post by snibgo »

From the filename, you can make a new string that contains the same characters but separated by the two characters "\n".

This is a scripting problem, not specific to ImageMagick.

For example, a Windows BAT script:

Code: Select all

set strNq=%~1

set strLen=0

set NewStr=

if "%strNq%"=="" exit /B 1 

:loop
set C=!strNq:~%strLen%,1!

if defined C (
  set NewStr=%NewStr%%C%\n
  set /A strLen+=1
  goto loop
)

echo strLen=%strLen%  NewStr=%NewStr%
snibgo's IM pages: im.snibgo.com

Robin55
Posts: 36
Joined: 2018-03-19T15:29:46-07:00
Authentication code: 1152

Re: How can you add vertical text in batch using the filename.

Post by Robin55 »

sorry@snibgo I do not understand how to use your bat file? what am I missing please?

Robin55
Posts: 36
Joined: 2018-03-19T15:29:46-07:00
Authentication code: 1152

Re: How can you add vertical text in batch using the filename.

Post by Robin55 »

Can Anyone else help me with this problem?

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can you add vertical text in batch using the filename.

Post by snibgo »

I showed code that creates an environment variable with "\n" after each character. You can incorporate that in your original script, for example:

Code: Select all

for %%F in (Front Covers\*.png) do (

  call :StrBackN "%%~nF"

  %IMG7%magick ^
    "Front Covers\%%~nF.png" ^
    ^( -background transparent -size 500x500 ^
       -font Arial-Unicode-MS -fill black -gravity west label:"!NewStr!" ^
       -trim ^
    ^) -gravity Southwest -geometry +80+55 -composite ^
    "Covers\%%~nF.png"
)

exit /B 0

::-------------------
:StrBackN

set strNq=%~1

set strLen=0

set NewStr=

if "%strNq%"=="" exit /B 1 

:loop
set C=!strNq:~%strLen%,1!

if defined C (
  set NewStr=%NewStr%%C%\n
  set /A strLen+=1
  goto loop
)

exit /B 0
snibgo's IM pages: im.snibgo.com

Robin55
Posts: 36
Joined: 2018-03-19T15:29:46-07:00
Authentication code: 1152

Re: How can you add vertical text in batch using the filename.

Post by Robin55 »

I'm afraid I can not get this script to work @snibgo.

I have tried it with the "Do" and "Do Magick" Commands but so far I am getting no script on my .PNG's.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can you add vertical text in batch using the filename.

Post by snibgo »

Robin55 wrote:I'm afraid I can not get this script to work @snibgo.
What happens, or doesn't happen?
Robin55 wrote:I have tried it with the "Do" and "Do Magick" Commands but so far I am getting no script on my .PNG's.
I don't understand. Do you mean you changed the script I gave you? Why?
snibgo's IM pages: im.snibgo.com

Robin55
Posts: 36
Joined: 2018-03-19T15:29:46-07:00
Authentication code: 1152

Re: How can you add vertical text in batch using the filename.

Post by Robin55 »

I just changed it to see what would happen seeing as I couldn't get it to work normally, I was just experimenting

When I run your script I get the CMD pop up window and it shows some writing very briefly and closes. It doesn't appear to be doing anything.

Thank you for your help with this so far.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can you add vertical text in batch using the filename.

Post by snibgo »

I suggest you run the script (and any other scripts) by: (1) open a command window, aka command prompt aka console, then (b) type the name of the script and press the return key.
snibgo's IM pages: im.snibgo.com

Locked