determining offset in magick++ crop operation

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
tsftd
Posts: 28
Joined: 2012-01-14T11:46:55-07:00
Authentication code: 8675308

determining offset in magick++ crop operation

Post by tsftd »

As part of a larger program, I'm using imagemagick+jpegtran to hack up a "lossless" jpeg trim operation. Essentially, I run a trim operation, take the results, and then apply it through jpegtran (after altering the math a bit to fit within jpegtran crop constraints). I am in the process of updating the program from more or less simple scripting (running an external imagemagick executable) to proper magick++ API, to increase the speed/lower resources used. Unfortunately, while I can do it with the executable, I can't seem to find the information I need within the API. Using :

Code: Select all

Image file(input);
file.colorFuzz(fuzz*65535/100);
file.trim();
cout << "ores: " << file.baseColumns() << "x" << file.baseRows() << endl;
cout << "nres: " << file.columns() << "x" << file.rows() << endl;
Output:

Code: Select all

ores: 1548x1084
nres: 512x656
I can find out the original and post-crop resolutions, but I can't seem to find the offset it was cropped at. granted, i could just color a pixel at the top, trim, note, and repeat for bottom, left, and right. but that's a lot more work to do something I'm sure is available somewhere (given that you can access it from the commandline).

Any help would be much appreciated!
jaap
Posts: 1
Joined: 2012-06-22T00:19:40-07:00
Authentication code: 13

Re: determining offset in magick++ crop operation

Post by jaap »

That's funny! I ran into the same problem too yesterday!

I just discovered that the function boundingbox() will give you the required information. You have to run it before you run trim().

Code: Select all

Image finalimage("out.png");
Geometry *g1 = new Geometry();
*g1 = finalimage.boundingBox();
finalimage.trim();
cout << "Trimmed from " << finalimage.baseColumns() << "x" << finalimage.baseRows();
cout << "to: " << finalimage.columns() << "x" << finalimage.rows() << " with offset " << g1->xOff() << "x" << g1->yOff() << endl;
more info about the output of boundingBox: http://www.imagemagick.org/Magick++/Geometry.html
tuxic.nl - open source hosting and network solutions
fablabtruck.nl - mobile digital fabrication lab
laoslaser.org - open source software for laser cutters
tsftd
Posts: 28
Joined: 2012-01-14T11:46:55-07:00
Authentication code: 8675308

Re: determining offset in magick++ crop operation

Post by tsftd »

thank you so much!

youre a lifesaver
Post Reply