Page 1 of 2

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

Posted: 2020-03-19T13:28:07-07:00
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"

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

Posted: 2020-03-19T13:42:36-07:00
by fmw42
If you want to write ABC vertically, use "A\nB\nC" as your text string using new line \n between characters.

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

Posted: 2020-03-19T13:49:54-07:00
by Robin55
Thanks @fmw42 unfortunately I am not using English spelling and also all the files have a different names

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

Posted: 2020-03-19T14:01:33-07:00
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

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

Posted: 2020-03-19T14:29:52-07:00
by Robin55
@fmw42 would you be able to show me how I would write that command please?

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

Posted: 2020-03-19T14:51:07-07:00
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

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

Posted: 2020-03-19T14:56:47-07:00
by Robin55
That's no good to me I am afraid. I need to be able to use the file name not individual words....

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

Posted: 2020-03-19T15:38:34-07:00
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%

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

Posted: 2020-03-19T15:45:19-07:00
by Robin55
sorry@snibgo I do not understand how to use your bat file? what am I missing please?

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

Posted: 2020-03-20T02:00:35-07:00
by Robin55
Can Anyone else help me with this problem?

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

Posted: 2020-03-20T06:21:20-07:00
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

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

Posted: 2020-03-20T06:59:05-07:00
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.

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

Posted: 2020-03-20T07:20:47-07:00
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?

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

Posted: 2020-03-20T07:28:01-07:00
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.

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

Posted: 2020-03-20T07:48:22-07:00
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.