convert -crop

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
ancou82

convert -crop

Post by ancou82 »

I use the next in my code but nothing is returned

Code: Select all

	 Runtime runtime = Runtime.getRuntime();
	 String cmd=="convert -crop 600x400+0x600 /capturas/Capture184.bmp /capturas/idof.bmp ";
	  Process process = runtime.exec("convert -crop 600x400+0x600 /capturas/Capture184.bmp /capturas/idof.bmp "); 
	 // Process process = runtime.exec(cmd); 
	  int exitVal = process.waitFor(); 
What's wrong here?

thanks in advanced
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: convert -crop

Post by Bonzo »

Code: Select all

String cmd=="convert -crop 600x400+0x600 /capturas/Capture184.bmp /capturas/idof.bmp ";
Should be:

Code: Select all

String cmd=="convert -crop 600x400+0+600 /capturas/Capture184.bmp /capturas/idof.bmp ";
600x400 is the crop size and the +0+600 is the offset - in your case the top left corner.

See: http://www.imagemagick.org/script/comma ... s.php#crop
ancou82

Re: convert -crop

Post by ancou82 »

Bonzo wrote:

Code: Select all

String cmd=="convert -crop 600x400+0x600 /capturas/Capture184.bmp /capturas/idof.bmp ";
Should be:

Code: Select all

String cmd=="convert -crop 600x400+0+600 /capturas/Capture184.bmp /capturas/idof.bmp ";
600x400 is the crop size and the +0+600 is the offset - in your case the top left corner.

See: http://www.imagemagick.org/script/comma ... s.php#crop

that is not the problem because when i execute the last sentence in the cmd creates a new image, but when i try to execute thorugh java code nothing is created. It just do nothing.

It's strange because i said before, the same sentence works con cmd and not working in java code

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

Re: convert -crop

Post by fmw42 »

your need to put the input image before -crop

convert input -crop WxH+X+Y +repage output

the repage removes the virtual canvas that may be causing problems as well.

see

http://www.imagemagick.org/Usage/crop/#crop_repage

http://www.imagemagick.org/Usage/basics/#cmdline
ancou82

Re: convert -crop

Post by ancou82 »

fmw42 wrote:your need to put the input image before -crop

convert input -crop WxH+X+Y +repage output

the repage removes the virtual canvas that may be causing problems as well.

see

http://www.imagemagick.org/Usage/crop/#crop_repage

http://www.imagemagick.org/Usage/basics/#cmdline

Code: Select all

	    	 Runtime runtime = Runtime.getRuntime();
	    	 Process process = runtime.exec("convert /capturas/Capture184.bmp -crop 600x400+0x600 +repage /capturas/idof.bmp");
It doesn't work when calling in java code, but in cmd it works too

What can be the problem?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert -crop

Post by fmw42 »

probably need the full path to convert.

typically

/usr/local/bin/convert

or

/usr/bin/convert


use

which convert to find where it is located and append the full path to convert.
ancou82

Re: convert -crop

Post by ancou82 »

fmw42 wrote:probably need the full path to convert.

typically

/usr/local/bin/convert

or

/usr/bin/convert


use

which convert to find where it is located and append the full path to convert.



Now it works but I still have a problem.

The call is not working always. I have to execute a few times to get an image.

One more time...i don't understand why.

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

Re: convert -crop

Post by fmw42 »

I don't understand why you would have inconsistency unless perhaps you have more than one version of IM installed on your system or some of your images are corrupted. But this is beyond me. Someone more knowledgeable will need to help here.
ancou82

Re: convert -crop

Post by ancou82 »

fmw42 wrote:I don't understand why you would have inconsistency unless perhaps you have more than one version of IM installed on your system or some of your images are corrupted. But this is beyond me. Someone more knowledgeable will need to help here.

I think the problem is solved.

Maybe wasn't working properly because I have more runtime executing before convert -crop and something went wrong, now I write process.waitfor() and everything seems to work fine.

Thanks a lot everybody
Post Reply