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?".
ancou82

convert -crop

Postby ancou82 » 2010-10-26T09:25:25-07:00

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: 2259
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England
Contact:

Re: convert -crop

Postby Bonzo » 2010-10-26T09:37:17-07:00

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

Postby ancou82 » 2010-10-26T09:54:10-07:00

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: 15147
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA
Contact:

Re: convert -crop

Postby fmw42 » 2010-10-26T10:03:54-07:00

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

Postby ancou82 » 2010-10-26T10:25:03-07:00

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: 15147
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA
Contact:

Re: convert -crop

Postby fmw42 » 2010-10-26T12:51:20-07:00

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

Postby ancou82 » 2010-10-27T01:10:41-07:00

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: 15147
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA
Contact:

Re: convert -crop

Postby fmw42 » 2010-10-27T10:13:51-07:00

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

Postby ancou82 » 2010-10-28T05:05:22-07:00

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


Return to “Users”

Who is online

Users browsing this forum: Bing [Bot], fmw42, smroczek, Yahoo [Bot] and 12 guests