Robert Pollak
Robert Pollak

Reputation: 4175

Can Imagemagick's inline crop and scale operations be combined?

As described on the Imagemagick site, "Inline Image Crop" works like this:

convert '*.jpg[120x120+10+5]' thumbnail%03d.png

Additionally, there is an inline scale operation, looking like this:

pattern:bricks[200%]

Can these two operations be combined?

I have tried

montage -tile 2x1 A.png B.png[200%50x50+10+10] out.png

and

montage -tile 2x1 A.png B.png[200%][50x50+10+10] out.png

, but these don't work.

Upvotes: 0

Views: 96

Answers (2)

Mark Setchell
Mark Setchell

Reputation: 208077

Not sure whether your question is about cropping or scaling or montage, but if you mean you want to load two images and crop/scale individually then montage them, you can do:

convert \
   \( image1.jpg -crop ... -scale ... \) \
   \( image2.jpg -crop ... -scale ... \) \
   +append result.jpg

Upvotes: 1

emcconville
emcconville

Reputation: 24439

Can these two operations be combined?

No. At least not in the inline short-cut technique you're attempting.

It would be better to extent the commands out as

convert *.jpg -crop 120x120+10+5 -scale 200% thumbnail%03d.png

I believe that IM parses the inline as a single geometry on the image_info->extract structure. The GeometryInfo will have conflicting data values if you attempt to mix more than one geometry string.

For testing, Take the following example application.

// test_geometry.c
#include <stdio.h>
#include <magick/MagickCore.h>

int main(int argc, const char * argv[]) {
    // Set-up
    MagickStatusType flags = 0;
    GeometryInfo geometry_info = {0.0, 0.0, 0.0, 0.0, 0.0};
    // Parse first argument
    flags = ParseGeometry(argv[1], &geometry_info);
    // Dump what was parsed (this code was copied from magick/geomerty.c)
    printf("ParseGeometry...\n");
    printf("Flags: %c %c %s %s %s\n",
           (flags & RhoValue) ? 'W' : ' ',(flags & SigmaValue) ? 'H' : ' ',
           (flags & XiValue) ? ((flags & XiNegative) ? "-X" : "+X") : "  ",
           (flags & PsiValue) ? ((flags & PsiNegative) ? "-Y" : "+Y") : "  ",
           (flags & ChiValue) ? ((flags & ChiNegative) ? "-Z" : "+Z") : "  ");
    printf("Geometry: %lg,%lg,%lg,%lg,%lg\n",geometry_info.rho,
           geometry_info.sigma,geometry_info.xi,geometry_info.psi,
           geometry_info.chi);
    return 0;
}

Compiling the above with

clang -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/local/include/ImageMagick-6 \
      -L/usr/local/lib -lMagickCore-6.Q16 \
      test_geometry.c -o test_geometry

If we run the following test cases 120x120+10+5

./test_geometry 120x120+10+5
ParseGeometry...
Flags: W H +X +Y   
Geometry: 120,120,10,5,0

Works as expected, and what about 200%?

./test_geometry 200%
ParseGeometry...
Flags: W   
Geometry: 200,200,0,0,0

Also what we would expect. But what about 200%50x50+10+10?

./test_geometry 120x120+10+5
ParseGeometry...
Flags: W H +X +Y   
Geometry: 20050,50,10,10,0

Whoops! I don't believe a width of 20,050 was expected.

Upvotes: 0

Related Questions