MikeWey / DMagick

An ImageMagick binding for the D Programming Language.
zlib License
17 stars 4 forks source link

Image.crop add offset to image #9

Closed trikko closed 11 years ago

trikko commented 11 years ago

import dmagick.Image; import dmagick.Geometry;

void main(string[] s) { Image i = new Image("/tmp/300.png");

    int newW = cast(int)(i.view.width*0.85);
    int newH = cast(int)(i.view.height * 0.85);
    Geometry g = Geometry(newW,newH,(i.view.width-newW)/2,(i.view.height-newH)/2);

    i.crop(g);
    i.write("/tmp/cropped.png");

}

dmd 2.061 dmagick from trunk. Ubuntu 12.10.

Try to open "cropped" image with gimp, it explains you the problem.

300 cropped

MikeWey commented 11 years ago

crop retains the size virtual canvas or page, and sets the offset of the image in this virtual canvas.

You may want to use Image.excerpt for what you are trying to do.

trikko commented 11 years ago

You're right, but I have same problem with rotate, for example. I move image layer outside canvas... Why rotate doesn't enlarge inage canvas size?

MikeWey commented 11 years ago

When i try rotating an image the canvas does get resized, but it does set an offset for the image. Is that also the case for you? if so you can try resetting the page offset:

img.page = Geometry(img.columns, img.rows, 0, 0);

the with and height seem to be ignored for an png so they could be 0 also.

trikko commented 11 years ago

Ok, that's fine :+1: