/** * Save the GD image ($src_img) to the desired location ($dest_path) with the sizing arguments * */ function createImg($src_img, $dest_path, $dst_x, $dst_y, $off_w, $off_h, $dst_w, $dst_h, $old_x, $old_y, $new_w = false, $new_h = false) { if (!$new_w) { $new_w = $dst_w; } if (!$new_h) { $new_h = $dst_h; } $dst_img = imagecreatetruecolor($new_w, $new_h); if (!$dst_img) { trigger_error('dst_img not created'); return false; } $img_type = thumbnail::getType($dest_path); // allow gif & png to have transparent background if (function_exists('imagesavealpha')) { if ($img_type == 'gif' || $img_type == 'png') { imagealphablending($dst_img, false); imagesavealpha($dst_img, true); //php 4.3.2+ $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127); imagefilledrectangle($dst_img, 0, 0, $dst_x, $dst_y, $transparent); } } if (!imagecopyresampled($dst_img, $src_img, $dst_x, $dst_y, $off_w, $off_h, $dst_w, $dst_h, $old_x, $old_y)) { trigger_error('copyresample failed'); imagedestroy($dst_img); imagedestroy($src_img); return false; } imagedestroy($src_img); return thumbnail::SrcToImage($dst_img, $dest_path, $img_type); }
/** * Save the GD image ($src_img) to the desired location ($dest_path) with the sizing arguments * */ static function createImg($src_img, $dest_path, $dst_x, $dst_y, $off_w, $off_h, $dst_w, $dst_h, $old_x, $old_y, $new_w = false, $new_h = false) { if (!$new_w) { $new_w = $dst_w; } if (!$new_h) { $new_h = $dst_h; } $dst_img = imagecreatetruecolor($new_w, $new_h); if (!$dst_img) { trigger_error('dst_img not created'); return false; } $img_type = thumbnail::getType($dest_path); // allow gif & png to have transparent background switch ($img_type) { case 'gif': case 'png': $dst_img = self::Transparency($dst_img); break; } if (!imagecopyresampled($dst_img, $src_img, $dst_x, $dst_y, $off_w, $off_h, $dst_w, $dst_h, $old_x, $old_y)) { trigger_error('copyresample failed'); imagedestroy($dst_img); imagedestroy($src_img); return false; } imagedestroy($src_img); return thumbnail::SrcToImage($dst_img, $dest_path, $img_type); }