source : https://drupal.org/node/422836
Here is the complete function from imageapi_gd.module with the FIX in.
The fix resolves the issue when creating images a black background gets generated on scale + crop - change the rgb values to whatever you what the bg color to be ;)
Hope this helps someone.
/**
* Crop an image using the GD toolkit.
*
* @param $image
* An image object. The $image->resource, $image->info['width'], and
* $image->info['height'] values will be modified by this call.
* @param $x
* The starting x offset at which to start the crop, in pixels.
* @param $y
* The starting y offset at which to start the crop, in pixels.
* @param $width
* The width of the cropped area, in pixels.
* @param $height
* The height of the cropped area, in pixels.
* @return
* TRUE or FALSE, based on success.
*/
function imageapi_gd_image_crop
(&$image, $x, $y, $width, $height) {
$res = imageapi_gd_create_tmp
($image, $width, $height);
if (!imagecopyresampled($res, $image->resource, 0, 0, $x, $y, $width, $height, $width, $height)) {
return FALSE;
}
// _mR
imagefill($res, 0, 0, imagecolorallocate($res, 255, 255, 255));
$new = imageapi_gd_create_tmp
($image, $width, $height);
imagecopy($new, $res, 0, 0, 0, 0, ($width + $x), ($height + $y));
$res = $new;
// _mR
// Destroy the original image and return the modified image.
imagedestroy($image->resource);
$image->resource = $res;
$image->info['width'] = $width;
$image->info['height'] = $height;
return TRUE;
}
Post new comment