diff -urp ./imageapi-5.x-1.1/imageapi_gd.module ./imageapi/imageapi_gd.module --- ./imageapi-5.x-1.1/imageapi_gd.module 2008-05-12 21:54:48.000000000 +0400 +++ ./imageapi/imageapi_gd.module 2008-05-27 10:34:09.000000000 +0400 @@ -44,10 +44,16 @@ function imageapi_gd_image_close($image, function imageapi_gd_image_crop(&$image, $x, $y, $width, $height) { $res = _gd_create_tmp($image, $width, $height); + $src_width=min($image->info['width'],$width); + $src_height=min($image->info['height'],$height); + $src_x=max(0,$x); + $src_y=max(0,$y); + $dst_x=max(0,-$x); + $dst_y=max(0,-$y); + if (!imagecopy($res, $image->res, $dst_x, $dst_y, $src_x, $src_y, $src_width, $src_height)) { + return false; + } - if (!imagecopyresampled($res, $image->res, 0, 0, $x, $y, $width, $height, $width, $height)) { - return false; - } // destroy the original image and return the modified image. imagedestroy($image->res); $image->res = $res; @@ -128,26 +134,15 @@ if (!function_exists('imagefilter')) { */ function _gd_create_tmp($image, $width, $height) { $res = imagecreatetruecolor($width, $height); + $color=array('red'=>255,'green'=>255,'blue'=>255,'alpha'=>0); if ($image->info['extension'] == 'gif' || $image->info['extension'] == 'jpg') { // grab transparent color index from src. - $transparent = imagecolortransparent($image->res); - - // if indexed transparency, lets preserve it. - if ($transparent >= 0) { - // get color(r,g,b) for index; - $transparent = imagecolorsforindex($image->res, $transparent); - // allocate to new image and get new index. - $transparent = (isset($color['alpha'])) - ? imagecolorallocatealpha($res, $color['red'], $color['green'], $color['blue'], $color['alpha']) - : imagecolorallocate($res, $color['red'], $color['green'], $color['blue']); - - $transparent = imagecolorallocate($res, $transparent['red'], $transparent['green'], $transparent['blue']); - // flood with our new transparent color. - imagefill($res, 0, 0, $transparent); - // tell the new image which color is transparent. - imagecolortransparent($res, $transparent); - } + $transparent = (isset($color['alpha'])) + ? imagecolorallocatealpha($res, $color['red'], $color['green'], $color['blue'], $color['alpha']) + : imagecolorallocate($res, $color['red'], $color['green'], $color['blue']); + imagefilledrectangle($res, 0, 0, $width, $height, $transparent); + imagecolortransparent($res, $transparent); } elseif ($image->info['extension'] == 'png') { imagealphablending($res, false);