Reply to Re: Problem with image_crop with negative value

Re: Problem with image_crop with negative value new!
by colin, 16 years, 8 months ago
It is a bug, thank you for reporting it.

The error occurs because when the class crops, with negative margins, it creates up extra space, which by default is black. PHP image_file() function fills that area, but spills on the picture itself if it contains a contiguous black area.

To solve it, change the following into:
// fill in from the edge of the negative margin
if ($ct < 0) imagefill($tmp, round($this->image_dst_x / 2), 1, $fill);
if ($cr < 0) imagefill($tmp, $this->image_dst_x - 1, round($this->image_dst_y / 2), $fill);
if ($cb < 0) imagefill($tmp, round($this->image_dst_x / 2), $this->image_dst_y - 1, $fill);
if ($cl < 0) imagefill($tmp, 1, round($this->image_dst_y / 2), $fill);
to
// fills eventual negative margins
if ($ct < 0) imagefilledrectangle($tmp, 0, 0, $this->image_dst_x, -$ct, $fill);
if ($cr < 0) imagefilledrectangle($tmp, $this->image_dst_x + $cr, 0, $this->image_dst_x, $this->image_dst_y, $fill);
if ($cb < 0) imagefilledrectangle($tmp, 0, $this->image_dst_y + $cb, $this->image_dst_x, $this->image_dst_y, $fill);
if ($cl < 0) imagefilledrectangle($tmp, 0, 0, -$cl, $this->image_dst_y, $fill);
This will be added in the next release.

As for the images not being created quickly enough, it is strange. When the class dumps the image, it does so, then only the script continues. So when the page with the link to the image is sent to the browser, the image has been indeed created. Maybe your live server uses a filer, and the files need a little bit of time to synchronise.

(edit: implemented a better fix)Reply

Your reply

Name *
Email 
Title *
Text *
CAPTCHA image
Enter the code displayed on the image:
Click on the image to generate another one if it is hard to read it. The case is important