Split Image in 2. Then apply other commands. Stack problem?

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
B_Gaspar
Posts: 16
Joined: 2013-07-25T15:34:49-07:00
Authentication code: 6789

Split Image in 2. Then apply other commands. Stack problem?

Post by B_Gaspar »

Hi to all

Imagemagick 6.9.3.-7 Q16 x64 on Windows 7 x64

I'm trying to split an image in 2 (-crop), then on the first part apply a rotate and a trim. I'm having trouble with this. There's something in my logic, I can't seem to apply the commands in isolation.

If I do the following and get the following information
"identify -crop 2816x4344 C:\AsFarpas\AsFarpas+00000032.tif"

C:\AsFarpas\AsFarpas+00000032.tif[0] TIFF 6314x4346=>2816x4344 6314x4346+0+0 8-b
it Grayscale Gray 0.265u 0:00.139
C:\AsFarpas\AsFarpas+00000032.tif[1] TIFF 6314x4346=>2816x4344 6314x4346+2816+0
8-bit Grayscale Gray 0.172u 0:00.100
C:\AsFarpas\AsFarpas+00000032.tif[2] TIFF 6314x4346=>682x4344 6314x4346+5632+0 8
-bit Grayscale Gray 0.125u 0:00.059
C:\AsFarpas\AsFarpas+00000032.tif[3] TIFF 6314x4346=>2816x2 6314x4346+0+4344 8-b
it Grayscale Gray 0.094u 0:00.049
C:\AsFarpas\AsFarpas+00000032.tif[4] TIFF 6314x4346=>2816x2 6314x4346+2816+4344
8-bit Grayscale Gray 0.125u 0:00.059
C:\AsFarpas\AsFarpas+00000032.tif[5] TIFF 6314x4346=>682x2 6314x4346+5632+4344 8
-bit Grayscale Gray 0.125u 0:00.059

I tried this.
"convert C:\AsFarpas\AsFarpas+00000032.tif +repage -crop 2816.572185751581x4346 +repage -delete 2-20"
I discard parts 2 to 5.

Then I wanted to apply the following in isolation to C:\AsFarpas\AsFarpas+00000032.tif[0] and save
" -background black -rotate 0.5 -bordercolor black -border 1x1 -fuzz 80% -trim +repage -shave 0x20 -crop +60+0 -crop -100+0 +repage
-write c:\brunoout\UMALINHA_A.tif

Then I wanted to apply the following in isolation to C:\AsFarpas\AsFarpas+00000032.tif[1] and save
"-background black -rotate -0.5625 -bordercolor black -border 1x1 -fuzz 80% -trim +repage -shave 0x20 -crop +100+0 -crop -60+0 +repage ^
-write c:\brunoout\UMALINHA_B.tif

I've tested all the results individually and they are ok. I wanted to incorporate this into only one command line.

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

Re: Split Image in 2. Then apply other commands. Stack problem?

Post by snibgo »

"-rotate" and other operations apply to all the images in the current list. If you have two images in the list, they will both be rotated.

If you have two images, but want only one rotated, start a new list with "(". Then clone in whichever you want. Now you have only one image in the current list, so rotate and do whatever you want to that image.

When you ")", all images from the nested list are copied to the outer list. "-delete" the old image.

Does that help? If not, please show the individual commands you want to string together. (Show the complete commands.)
snibgo's IM pages: im.snibgo.com
B_Gaspar
Posts: 16
Joined: 2013-07-25T15:34:49-07:00
Authentication code: 6789

Re: Split Image in 2. Then apply other commands. Stack problem?

Post by B_Gaspar »

Thanks a lot. I wasn't really getting the stack part of the images, I since I had those initial ones AsFarpas+00000032.tif[0] and AsFarpas+00000032.tif[1] I thought that the -clone was just duplicating again.
So here is the full command line, that does exactly what I want. but there's an error in the end.

"convert C:\AsFarpas\AsFarpas+00000032.tif +repage -crop 2816.572185751581x4346 +repage -delete 2-20 ^
( -clone 0 -background black -rotate 0.5 -bordercolor black -border 1x1 -fuzz 80% -trim +repage -shave 0x20 -crop +60+0 -crop -100+0 +repage ^
-write c:\brunoout\UMALINHA_A.tif -delete 0--1 ) ^
( -clone 1 -background black -rotate -0.5625 -bordercolor black -border 1x1 -fuzz 80% -trim +repage -shave 0x20 -crop +100+0 -crop -60+0 +repage ^
-write c:\brunoout\UMALINHA_B.tif -delete 0--1 )

ERROR
convert.exe: unbalanced parenthesis `)' @ error/convert.c/ConvertImageCommand/32
47.

So I get the results right, images UMALINHA_A.tif and UMALINHA_B.tif, but get this error.
Is this the best way to achieve this result?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Split Image in 2. Then apply other commands. Stack problem?

Post by snibgo »

"convert" needs to end with an output for any images. But this can be "null:".
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Split Image in 2. Then apply other commands. Stack problem?

Post by GeeMack »

B_Gaspar wrote: 2017-07-29T10:16:31-07:00So I get the results right, images UMALINHA_A.tif and UMALINHA_B.tif, but get this error.
Is this the best way to achieve this result?
IM wants the last thing in the command to be an output image name, and outside the parentheses. You should be able to just add "null:" after the last parentheses to make your command work. The way you have it, it writes the images you want, and IM will be happy to write the final output to "null:". It's a sort of empty image IM uses for a few special purposes.
B_Gaspar
Posts: 16
Joined: 2013-07-25T15:34:49-07:00
Authentication code: 6789

Re: Split Image in 2. Then apply other commands. Stack problem?

Post by B_Gaspar »

Thank you for all the help. Now it's perfect for my needs.
Post Reply