diff -urp ../imageapi-5.x-1.2/imageapi_gd.module ./imageapi_gd.module --- ../imageapi-5.x-1.2/imageapi_gd.module 2008-05-29 20:33:32.000000000 +0400 +++ ./imageapi_gd.module 2008-09-02 13:27:10.000000000 +0400 @@ -28,6 +28,14 @@ function imageapi_gd_settings_form() { '#default_value' => variable_get('image_jpeg_quality', 75), '#field_suffix' => '%', ); + $form['image_crop_background'] = array( + '#type' => 'textfield', + '#title' => t('Background color'), + '#description' => t('Define the image background color for manipulations. Values need to be hexdecimal, eg #FFFFFF is white.'), + '#size' => 7, + '#maxlength' => 7, + '#default_value' => variable_get('image_crop_background', "#FFFFFF"), + ); return system_settings_form($form); } @@ -44,8 +52,13 @@ function imageapi_gd_image_close($image, function imageapi_gd_image_crop(&$image, $x, $y, $width, $height) { $res = _gd_create_tmp($image, $width, $height); - - if (!imagecopyresampled($res, $image->res, 0, 0, $x, $y, $width, $height, $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; } // destroy the original image and return the modified image. @@ -127,27 +140,23 @@ if (!function_exists('imagefilter')) { * @todo: add bgcolor setting to add a default background color. */ function _gd_create_tmp($image, $width, $height) { + static $bg_color; $res = imagecreatetruecolor($width, $height); - - if ($image->info['extension'] == 'gif' || $image->info['extension'] == 'jpg') { - // grab transparent color index from src. - $transparent = imagecolortransparent($image->res); + if(!isset($bg_color)) { + $bg_color_html=variable_get('image_crop_background', '#FFFFFF'); + preg_match('/\#?(\w\w)(\w\w)(\w\w)/',$bg_color_html,$matches); + $bg_color['red']=hexdec($matches[1]); + $bg_color['green']=hexdec($matches[2]); + $bg_color['blue']=hexdec($matches[3]); + unset($matches); + } - // 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); - } + if ($image->info['extension'] == 'gif' || $image->info['extension'] == 'jpg') { + $transparent = (isset($bg_color['alpha'])) + ? imagecolorallocatealpha($res, $bg_color['red'], $bg_color['green'], $bg_color['blue'], $bg_color['alpha']) + : imagecolorallocate($res, $bg_color['red'], $bg_color['green'], $bg_color['blue']); + imagefilledrectangle($res, 0, 0, $width, $height, $transparent); + imagecolortransparent($res, $transparent); } elseif ($image->info['extension'] == 'png') { imagealphablending($res, false); diff -urp ../imageapi-5.x-1.2/imageapi.module ./imageapi.module --- ../imageapi-5.x-1.2/imageapi.module 2008-06-08 03:02:18.000000000 +0400 +++ ./imageapi.module 2008-09-02 13:26:23.000000000 +0400 @@ -270,14 +270,14 @@ function imageapi_image_crop(&$image, $x if (empty($width)) $width = $height * $aspect; // Ensure target image size is not greater than original size. - if ($width > $image->info['width']) { - $width = $image->info['width']; - $x = 0; - } - if ($height > $image->info['height']) { - $height = $image->info['height']; - $y = 0; - } +// if ($width > $image->info['width']) { +// $width = $image->info['width']; +// $x = 0; +// } +// if ($height > $image->info['height']) { +// $height = $image->info['height']; +// $y = 0; +// } return call_user_func($image->toolkit .'_image_crop', $image, $x, $y, $width, $height); }