How to slice up image of text

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

Re: How to slice up image of text

Post by snibgo »

damonm wrote:Where do I find the batch files?
On my web pages. There is a zip file with all my published BAT files (and some other stuff). I suggest you download and unzip it to some directory, that I suggest you don't use for anything else.
snibgo's IM pages: im.snibgo.com
damonm
Posts: 33
Joined: 2017-03-24T11:53:20-07:00
Authentication code: 1151

Re: How to slice up image of text

Post by damonm »

Thanks I found those.

I ran the command you specified and got a few errors (below). Am I missing some files that this needs? I did have to manually go grab guilfind.bat and guillotine.bat because they weren't in the big zip so I'm wondering if there is something else I may need to get as well? Thanks!!

C:\Program Files\ImageMagick-7.0.5-Q16\PICTBAT\Batch Files>call guillotine.bat p
at_crp.png subs_XX.png White 2 . 1

C:\Program Files\ImageMagick-7.0.5-Q16\PICTBAT\Batch Files>rem From image pat_cr
p.png, guillotines into pieces.
Invalid Parameter - -strip
Invalid Parameter - -quiet
guilFind: OFFSET=
Invalid Parameter - -quiet
'sed' is not recognized as an internal or external command,
operable program or batch file.
Files\ImageMagick-7.0.5-Q16\PICTBAT\Batch was unexpected at this time.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to slice up image of text

Post by snibgo »

damonm wrote:Invalid Parameter - -strip
This is an error message from Microsoft's "convert" program. You haven't done what I said earlier:
snibgo wrote:My scripts were written for IM v6. As you are using v7, you should prefix each IM command with "magick".
"sed" is a utility program, available from from the Cygwin installation (and probably many other places.
snibgo's IM pages: im.snibgo.com
damonm
Posts: 33
Joined: 2017-03-24T11:53:20-07:00
Authentication code: 1151

Re: How to slice up image of text

Post by damonm »

I want to say thank you, truly, for all your help, but I am sadly unable to get this method to work because the batch files seem to be calling directories that I don't have, or I have folders set up differently (I did create a folder called pictbat and put all the batch files there but that didn't help either). I also did a find and replace in all the "guillotine" batch files where I removed %im% and changed it to magick and while that helped it is still throwing all sorts of errors and saying it can't find directories such as "C:\program". I think your method is probably terrific, but I don't have the skills to modify this to make it work properly.

If a moderator would be so kind as to move this thread to the "for hire" forum, I am more than willing to pay someone to create a batch converter that does what I need and will loop through my multiple files to achieve the end result.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to slice up image of text

Post by snibgo »

damonm wrote:(I did create a folder called pictbat and put all the batch files there but that didn't help either.)
Did you create an environment variable called PICTBAT that points to that directory? Like this:

Code: Select all

set PICTBAT=\pictbat\
snibgo's IM pages: im.snibgo.com
damonm
Posts: 33
Joined: 2017-03-24T11:53:20-07:00
Authentication code: 1151

Re: How to slice up image of text

Post by damonm »

Well, I have to say, this is the least number of errors - now it says:

C:\Program Files\ImageMagick-7.0.5-Q16>rem From image pat_crp.png, guillotines into pieces.
The system cannot find the path specified.
The system cannot find the path specified.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to slice up image of text

Post by snibgo »

Good, we are getting there.

What command did you use to run the script?

Now, we'll track down where those messages came from.

In guillotine.bat, a line at the top says:

Code: Select all

@call echoOffSave
Comment this out by putting "rem" in front, like this:

Code: Select all

rem @call echoOffSave
Do the same in guilFind.bat and guilChop.bat.

Now, when you run the script, every command should be echoed to the screen before it is run. After a command that fails, you will get the error message.

That may show you what the problem is. If it doesn't, copy the error message and previous few commands, and paste them here.
snibgo's IM pages: im.snibgo.com
damonm
Posts: 33
Joined: 2017-03-24T11:53:20-07:00
Authentication code: 1151

Re: How to slice up image of text

Post by damonm »

OK, here's what it came up with - :

C:\Program Files\ImageMagick-7.0.5-Q16>rem From image pat_crp.png, guillotines into pieces.

C:\Program Files\ImageMagick-7.0.5-Q16>rem @call echoOffSave

C:\Program Files\ImageMagick-7.0.5-Q16>call \pictbat\setInOut pat_crp.png guil
The system cannot find the path specified.

C:\Program Files\ImageMagick-7.0.5-Q16>if not "subs_XX.png" == "" if not "subs_XX.png" == "." set OUTFILE=subs_XX.png

C:\Program Files\ImageMagick-7.0.5-Q16>call \pictbat\guilFind pat_crp.png . White 2 . 1
The system cannot find the path specified.

C:\Program Files\ImageMagick-7.0.5-Q16>if ERRORLEVEL 1 exit /B 1
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to slice up image of text

Post by snibgo »

damonm wrote:C:\Program Files\ImageMagick-7.0.5-Q16>call \pictbat\setInOut pat_crp.png guil
The system cannot find the path specified.
That means it looked for a directory (or "path" or "folder") called "pictbat" in the root of your current disk dive, and couldn't find it.

You said:
damonm wrote:(I did create a folder called pictbat and put all the batch files there but that didn't help either.)
But where is that folder? Did you put it at the root, or inside another folder? It doesn't matter where that folder is, provided the environment variable %PICTBAT% points to the same place, and it contains the bat files.

This command:

Code: Select all

dir %PICTBAT%
... should show you the contents of that directory. Until it does, the scripts won't work.


I see another problem looming, so I'll mention it now. Your current directory is:

Code: Select all

C:\Program Files\ImageMagick-7.0.5-Q16
This directory contains a space, between "program" and "files". I think spaces in directory names (or file names) are a really bad idea. Writing scripts to cope with spaces is tricky and I'm too lazy. So my scripts assume directories and filenames don't have spaces.

I suggest you run the script from a directory that has no spaces.

From that other directory, check that magick.exe is still on your path:

Code: Select all

magick -version
This should show the version number. But if you get an error message like:

Code: Select all

'magick' is not recognized as an internal or external command,
operable program or batch file.
... then you can temporarily add magick's directory to your system path:

Code: Select all

set PATH=C:\Program Files\ImageMagick-7.0.5-Q16;%PATH%
snibgo's IM pages: im.snibgo.com
damonm
Posts: 33
Joined: 2017-03-24T11:53:20-07:00
Authentication code: 1151

Re: How to slice up image of text

Post by damonm »

I made all the changes, and moved the imagemagick folder to the root (along with the pictbat folder). Everything runs now up until we get the first error here:

C:\ImageMagick-7.0.5-Q16>Magick convert C:\ImageMagick-7.0.5-Q16\pat_crp.png
-strip -rotate -90 -fuzz 2% -alpha set -transparent White -channel RGB -evaluate set 100% +channel -background Black -layers Flatten -scale "x1^!" -fuzz 0% -fill Black -opaque Black -fill White +opaque Black C:\ImageMagick-7.0.5-Q16\pat_crp_guil.png
convert: UnableToOpenConfigureFile `magic.xml' @ warning/configure.c/GetConfigureOptions/715.
convert: UnableToOpenConfigureFile `delegates.xml' @ warning/configure.c/GetConfigureOptions/715.
convert: UnableToOpenModuleFile 'C:\Program Files\ImageMagick-7.0.5-Q16\modules\coders\IM_MOD_RL_PNG_.dll': No such file or directory @ warning/module.c/GetMagickModulePath/680.
convert: NoDecodeDelegateForThisImageFormat `PNG' @ error/constitute.c/ReadImage/509.
convert: UnableToOpenConfigureFile `colors.xml' @ warning/configure.c/GetConfigureOptions/715.
convert: NoImagesDefined `C:\ImageMagick-7.0.5-Q16\pat_crp_guil.png' @ error/convert.c/ConvertImageCommand/3254.

C:\ImageMagick-7.0.5-Q16>if not "" == "" (set /A MG=/2 magick convert C:\ImageMagick-7.0.5-Q16\pat_crp_guil.png -negate -m
orphology Distance:-1 Chebyshev:1,1 -black-threshold !MG! -fill White +opaque Black -negate C:\ImageMagick-7.0.5-Q16\pat_crp_guil.png)

C:\ImageMagick-7.0.5-Q16>if "" == "1" magick convert C:\ImageMagick-7.0.5-Q16\pat_crp_guil.png -negate -morphology Distance:-1 Chebyshev:1,1 -auto-level -fill Black +opaque White -negate C:\ImageMagick-7.0.5-Q16\pat_crp_guil.png

C:\ImageMagick-7.0.5-Q16>for /F "usebackq tokens=3 delims=x+" %C in (`magick convert C:\ImageMagick-7.0.5-Q16\pat_crp_guil.png -quiet -bordercolor Black -border 1 -format "%@" info:`) do (set /A OFFSET=%C-1 )
convert: UnableToOpenBlob 'C:\ImageMagick-7.0.5-Q16\pat_crp_guil.png': No such file or directory @ error/blob.c/OpenBlob/3094.
convert: UnableToOpenBlob 'C:\ImageMagick-7.0.5-Q16\pat_crp_guil.png': No such file or directory @ error/blob.c/OpenBlob/3094.
convert: NoDecodeDelegateForThisImageFormat `PNG' @ error/constitute.c/ReadImage/509.
convert: NoImagesDefined `info:' @ error/convert.c/ConvertImageCommand/3254.

C:\ImageMagick-7.0.5-Q16>echo guilFind: OFFSET=guilFind: OFFSET=

C:\ImageMagick-7.0.5-Q16>magick convert C:\ImageMagick-7.0.5-Q16\pat_crp_guil.png -quiet -crop 0x1++0 +repage -morphology Thicken:-1 Skeleton -transparent White sparse-color:C:\ImageMagick-7.0.5-Q16\pat_crp_guil1.lis
convert: UnableToOpenBlob 'C:\ImageMagick-7.0.5-Q16\pat_crp_guil.png': No such file or directory @ error/blob.c/OpenBlob/3094.
convert: UnableToOpenBlob 'C:\ImageMagick-7.0.5-Q16\pat_crp_guil.png': No such file or directory @ error/blob.c/OpenBlob/3094.
convert: NoDecodeDelegateForThisImageFormat `PNG' @ error/constitute.c/ReadImage/509.
convert: NoImagesDefined `sparse-color:C:\ImageMagick-7.0.5-Q16\pat_crp_guil1.lis' @ error/convert.c/ConvertImageCommand/3254.

C:\ImageMagick-7.0.5-Q16>sed -e 's/ /\n/g' C:\ImageMagick-7.0.5-Q16\pat_crp_guil1.lis 1>C:\ImageMagick-7.0.5-Q16\pat_crp_guil2.lis
'sed' is not recognized as an internal or external command,operable program or batch file.

C:\ImageMagick-7.0.5-Q16>type C:\ImageMagick-7.0.5-Q16\pat_crp_guil2.lis
C:\ImageMagick-7.0.5-Q16>set nCUTS=0

C:\ImageMagick-7.0.5-Q16>(for /F "tokens=1 delims=, " %X in (C:\ImageMagick-7.0.5-Q16\pat_crp_guil2.lis) do (set /A V=%X+ echo !V! set /A nCUTS+=1) ) 1>C:\ImageMagick-7.0.5-Q16\pat_crp_guil.lis

C:\ImageMagick-7.0.5-Q16>echo guilFind: nCUTS=0guilFind: nCUTS=0

C:\ImageMagick-7.0.5-Q16>type C:\ImageMagick-7.0.5-Q16\pat_crp_guil.lis

C:\ImageMagick-7.0.5-Q16>call echoRestore
ECHO is on.

C:\ImageMagick-7.0.5-Q16>endlocal & set guilOUTFILE=C:\ImageMagick-7.0.5-Q16\pat_crp_guil.lis & set guilNUM_CUTS=0

C:\ImageMagick-7.0.5-Q16>if ERRORLEVEL 1 exit /B 1

C:\ImageMagick-7.0.5-Q16>call \pictbat\guilChop pat_crp.png C:\ImageMagick-7.0.5-Q16\pat_crp_guil.lis subs_XX.png 1

C:\ImageMagick-7.0.5-Q16>rem From image pat_crp.png and text file C:\ImageMagick-7.0.5-Q16\pat_crp_guil.lis,

C:\ImageMagick-7.0.5-Q16>rem makes 0 + 1 images,

C:\ImageMagick-7.0.5-Q16>rem named after pattern in subs_XX.png, substituting XX by a sequential number from zero.

C:\ImageMagick-7.0.5-Q16>rem 1 is 0 (guillotine vertically) or 1 (guillotine horizontally).

C:\ImageMagick-7.0.5-Q16>rem is 0 (discard canvas metadata) or 1 (re-calculatecanvas metadata).

C:\ImageMagick-7.0.5-Q16>rem

C:\ImageMagick-7.0.5-Q16>call \pictbat\setInOut pat_crp.png guil

C:\ImageMagick-7.0.5-Q16>setlocal DisableDelayedExpansion

C:\ImageMagick-7.0.5-Q16>set INFILE=C:\ImageMagick-7.0.5-Q16\pat_crp.png

C:\ImageMagick-7.0.5-Q16>if not exist "C:\ImageMagick-7.0.5-Q16\pat_crp.png" set INFILE=pat_crp.png

C:\ImageMagick-7.0.5-Q16>endlocal & set INFILE=C:\ImageMagick-7.0.5-Q16\pat_crp.png

C:\ImageMagick-7.0.5-Q16>setlocal DisableDelayedExpansion

C:\ImageMagick-7.0.5-Q16>if "" == "1" (
echo INFILE=C:\ImageMagick-7.0.5-Q16\pat_crp.png
echo INFILEBANG=C:\ImageMagick-7.0.5-Q16\pat_crp.png
echo OUTFILE=C:\ImageMagick-7.0.5-Q16\pat_crp_guil.png
echo INNAME=pat_crp
echo BASENAME=C:\ImageMagick-7.0.5-Q16\pat_crp
echo EXT=.png
)

C:\ImageMagick-7.0.5-Q16>endlocal

C:\ImageMagick-7.0.5-Q16>rem @call echoOffSave

C:\ImageMagick-7.0.5-Q16>set ORD_LIST=C:\ImageMagick-7.0.5-Q16\pat_crp_guil.lis


C:\ImageMagick-7.0.5-Q16>set FILE_PTN=subs_XX.png

C:\ImageMagick-7.0.5-Q16>if "subs_XX.png" == "" set FILE_PTN=

C:\ImageMagick-7.0.5-Q16>if "subs_XX.png" == "" set FILE_PTN=C:\ImageMagick-7.0.5-Q16\pat_crp_guilc_XX.png

C:\ImageMagick-7.0.5-Q16>set DIRN=1

C:\ImageMagick-7.0.5-Q16>if "1" == "." set DIRN=

C:\ImageMagick-7.0.5-Q16>if "1" == "" set DIRN=0

C:\ImageMagick-7.0.5-Q16>set CALC_CANV=1

C:\ImageMagick-7.0.5-Q16>if "1" == "." set CALC_CANV=

C:\ImageMagick-7.0.5-Q16>if "1" == "" set CALC_CANV=0

C:\ImageMagick-7.0.5-Q16>set SCR_FILE=guilc_tmp.bat

C:\ImageMagick-7.0.5-Q16>if 1 == 0 (set ROT_IN= set ROT_OUT=) else (set ROT_IN=-rotate -90 set ROT_OUT=-rotate 90)

C:\ImageMagick-7.0.5-Q16>if "0" == "0" (
rem Make one image set OUTNAME=!FILE_PTN:XX=0!
convert pat_crp.png !OUTNAME!
if ERRORLEVEL 1 exit /B 1
goto end
)
Invalid Parameter - subs_0.png

C:\ImageMagick-7.0.5-Q16>if ERRORLEVEL 1 exit /B 1

C:\ImageMagick-7.0.5-Q16>
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to slice up image of text

Post by snibgo »

damonm wrote:and moved the imagemagick folder to the root
Why did you do that?

You can install it to any place you want. I would always choose a directory with no spaces. But once you've installed it, you can't simply move it and expect it to work, unless you have installed the "portable" version.

At installation, IM makes an entry in the registry, giving the location of the XML and other files. But you have moved them, so IM asks the registry, gets the wrong directory, and can't find them.


In guilChop.bat, you have messed up an edit. Half way down, the original is:

Code: Select all

if "%guilNUM_CUTS%"=="0" (
  rem Make one image
  set OUTNAME=!FILE_PTN:XX=0!

  %IM%convert %1 !OUTNAME!
  if ERRORLEVEL 1 exit /B 1

  goto end
)
There are 5 lines within the "if". You have joined the first two into one, and you haven't changed "%IM%convert" into "magick convert".
snibgo's IM pages: im.snibgo.com
damonm
Posts: 33
Joined: 2017-03-24T11:53:20-07:00
Authentication code: 1151

Re: How to slice up image of text

Post by damonm »

Why would I move the folder? Because the installation doesn't ask you where you want to put it (even though the documentation says that is the first step, it's not present - at least in the first download available for Windows. It just installs to the default directory... So I wasn't really left with a lot of options. I could try a different version, maybe the 8 bit? I'll see if that actually gives me the option to install to a different directory.

The other item about the if statement, I manually went through the post and changed some word-wrapping, I just moved up one line manually to make the post more readable, but I will make sure and change the missed %IM%.
damonm
Posts: 33
Joined: 2017-03-24T11:53:20-07:00
Authentication code: 1151

Re: How to slice up image of text

Post by damonm »

I'm going to attempt again to make all this work, I interpreted from your above comments that I wouldn't be able to make it work if it was in the program files directory, but after seeing this I will try again...:
snibgo wrote: 2017-03-25T14:17:43-07:00 It shouldn't stop you running the scripts, if IM's files are in the installation directory, and that directory is on the system path.
damonm
Posts: 33
Joined: 2017-03-24T11:53:20-07:00
Authentication code: 1151

Re: How to slice up image of text

Post by damonm »

You were correct, it's having trouble with the space in between c:\program files\.

c:\Program Files\ImageMagick-7.0.5-Q16>endlocal & set INFILE=c:\Program Files\ImageMagick-7.0.5-Q16\pat_crp.png
The system cannot find the path specified.

Also, here:

c:\Program Files\ImageMagick-7.0.5-Q16>Magick convert c:\Program Files\ImageMa
gick-7.0.5-Q16\pat_crp.png -strip -rotate -90 -fuzz 2% -alpha set -tra
nsparent White -channel RGB -evaluate set 100% +channel -background Black -l
ayers Flatten -scale "x1^!" -fuzz 0% -fill Black -opaque Black -fill Whi
te +opaque Black pat_crp.png_guil.png
convert: unable to open image 'c:\Program': No such file or directory @ error/bl
ob.c/OpenBlob/3094.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadIm
age/509.
convert: unable to open image 'Files\ImageMagick-7.0.5-Q16\pat_crp.png': No such
file or directory @ error/blob.c/OpenBlob/3094.
convert: unable to open file `Files\ImageMagick-7.0.5-Q16\pat_crp.png' @ error/p
ng.c/ReadPNGImage/4354.
convert: no images defined `pat_crp.png_guil.png' @ error/convert.c/ConvertImage
Command/3254.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to slice up image of text

Post by snibgo »

I said above:
snibgo wrote:I suggest you run the script from a directory that has no spaces.
What directory are you in when you run the script?
snibgo's IM pages: im.snibgo.com
Post Reply