Thanks Joe!

It works perfectly.

    cout << "        Right: " << w << "x" << h << "+" << x << "+" << y <<
endl;
    cur = image;
    cur.crop( Geometry(w,h, x,y) );
    cur.page( Geometry(w,h, 0,0) );
    cur.quality(100);
    cur.write( "r.png" );

I love it when things are simple.

Peace,
Jonathan Jeffus

Psylus Development, LLC.

On Mon, May 12, 2008 at 4:16 PM, Joseph Huckaby <[EMAIL PROTECTED]> wrote:

> Hey Jonathan,
>
> I ran into this same problem a few years ago, and the fix is to reset
> the origin to 0x0 after a crop.  Here is how I do this in
> Image::Magick:
>
> #!/usr/bin/perl
> use strict;
> use Image::Magick;
> my $img = new Image::Magick;
> $img->Read("browse4.png");
> my $copy = $img->Clone();
> $copy->Crop(geometry=>'33x1960+1267+0');
>
> $copy->Set(
>     page => $copy->Get('width') . 'x' .  $copy->Get('height') . '+0+0'
> );
>
> $copy->Write("out.png");
>
> # Hope this helps!
>
> - Joe
>
>
>
>
> On Mon, May 12, 2008 at 12:00 PM, <[EMAIL PROTECTED]>
> wrote:
> > Send Magick-bugs mailing list submissions to
> >        [email protected]
> >
> > To subscribe or unsubscribe via the World Wide Web, visit
> >        http://studio.imagemagick.org/mailman/listinfo/magick-bugs
> > or, via email, send a message with subject or body 'help' to
> >        [EMAIL PROTECTED]
> >
> > You can reach the person managing the list at
> >        [EMAIL PROTECTED]
> >
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of Magick-bugs digest..."
> >
> > Today's Topics:
> >
> >   1. Re: PNG offset problem (Jonathan Jeffus)
> >
> >
> > ---------- Forwarded message ----------
> > From: "Jonathan Jeffus" <[EMAIL PROTECTED]>
> > To: [email protected]
> > Date: Mon, 12 May 2008 08:45:25 -0400
> > Subject: Re: [Magick-bugs] PNG offset problem
> > Hi,
> >
> > I hope I'm reporting this in the right place (and it's not a long
> squashed
> > bug, I couldn't find anything on it.) I tried at the Magick++ support
> forum
> > referenced here <http://www.imagemagick.org/Magick++/> but it does not
> seem
> > to be working.
> >
> > The bug ocurrs when you use image.crop() on an image and then save a
> PNG.  I
> > first verified it on 6.2.4 (standard for Debian Gutsy). Then I installed
> > 6.4.1-1 from source hoping it would go away, to no avail. I just hope
> I'm
> > not doing something dumb.
> >
> > // This is a simplified version that reproduces the bug.
> > // I reproduced it with several images my program works on
> > // The image in question is a 1300x2004 image, I'm trying to
> > // crop out a region on the right side of it.
> >
> > #include <cstdio>
> > #include <Magick++.h>
> > #include <iostream>
> > using namespace std;
> > using namespace Magick;
> > int main(int argc,char **argv) {
> >  Image image, cur;
> >  image.read( "browse4.png" );
> >  cur = image;
> >  cur.crop( Geometry(30,1960,1267, 0) );
> >  cur.modifyImage(); // Added this hoping the bug would go away by using
> it.
> >  cur.quality(100);
> >  cur.write( "out.png" );
> >  return 0;
> > }
> >
> > In this case, in.png is a 24bit png file with an alpha layer (an image
> > created by Inkscape 0.45, which seems to be using gtk_pixbuf for writing
> the
> > PNG.) Everything works great if I try to open out.png with a program
> that
> > uses libpng (like XV.) When I try to open it in GIMP 2.4.2 I get the
> message
> > "The PNG file specifies an offset that caused the layer to be positioned
> > outside the image."  The image which is then displayed is the correct
> width
> > and height but is otherwise blank. The bug also appears in PerlMagick.
> >
> > #!/usr/bin/perl
> > use strict;
> > use Image::Magick;
> > my $img = new Image::Magick;
> > $img->Read("browse4.png");
> > my $copy = $img->Clone();
> > $copy->Crop(geometry=>'33x1960+1267+0');
> > $copy->Write("out.png");
> >
> > Same thing in RMagick as well:
> > #!/usr/local/bin/ruby
> > require 'RMagick'
> > include Magick
> > img = Magick::Image::read("browse4.png").first
> > # 33x1960+1267+0
> > cur = img.crop(1267, 0, 33, 1960)
> > cur.write "out.png"
> >
> > Which means it's probably an ImageMagick bug? Is this a problem with the
> PNG
> > encoder? How do I remove the offset? I'd gladly provide the PNG in
> question,
> > although it ocurrs on any PNG I tried.
> >
> > Peace,
> > Jonathan Jeffus
> >
> > Psylus Development, LLC.
> >
> >
> > _______________________________________________
> > Magick-bugs mailing list
> > [email protected]
> > http://studio.imagemagick.org/mailman/listinfo/magick-bugs
> >
> >
>
_______________________________________________
Magick-bugs mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-bugs

Reply via email to