Index: branches/unlabeled/unlabeled-1.1.2/kernel/units/general/image_helper.php =================================================================== diff -u -N --- branches/unlabeled/unlabeled-1.1.2/kernel/units/general/image_helper.php (revision 0) +++ branches/unlabeled/unlabeled-1.1.2/kernel/units/general/image_helper.php (revision 4116) @@ -0,0 +1,120 @@ + 'imagecreatefromjpeg', + 'image/pjpeg' => 'imagecreatefromjpeg', + 'image/png' => 'imagecreatefrompng', + 'image/gif' => 'imagecreatefromgif', + ); + $func_to_use = $type_to_function[$type]; + + $this->ImageInfo = $image_info; + $this->FileName = $file_name; + return ( $this->Image = @$func_to_use($file_name) ) ? 1 : 0; + } + + function CopyResizedWithBackground($max_width, $max_height, $quality, $bg_color = false, $target_filename = false) + { + list($orig_width, $orig_height, $type, $attr) = $this->ImageInfo; + + $dst_img = imagecreatetruecolor($max_width, $max_height); + + if(!is_array($bg_color)) + { + $bg_color = Array(0xFF, 0xFF, 0xFF); + } + + list($r, $g, $b) = $bg_color; + $bg_color = imagecolorallocate($dst_img, $r, $g, $b); + imagefill($dst_img, 0 ,0, $bg_color); + + $too_large = ($orig_width > $max_width) || ($orig_height > $max_height); + + if($too_large) + { + $width_ratio = $max_width ? $max_width / $orig_width : 1; + $height_ratio = $max_height ? $max_height / $orig_height : 1; + $ratio = min($width_ratio, $height_ratio); + + $width = ceil($orig_width * $ratio); + $height = ceil($orig_height * $ratio); + } + else + { + $width = $orig_width; + $height = $orig_height; + } + + $dst_x = ceil(($max_width - $width) / 2); + $dst_y = ceil(($max_height - $height) / 2); + imagecopyresampled($dst_img, $this->Image, $dst_x, $dst_y, 0, 0, $width, $height, $orig_width, $orig_height); + + if($target_filename) + { + imagejpeg($dst_img, $target_filename, $quality); + } + else + { + $this->Image = $dst_img; + } + } + + function CopyResized($max_width, $max_height, $quality, $target_filename = false) + { + list($orig_width, $orig_height, $type, $attr) = $this->ImageInfo; + + $too_large = ($orig_width > $max_width) || ($orig_height > $max_height); + + if($too_large) + { + $width_ratio = $max_width ? $max_width / $orig_width : 1; + $height_ratio = $max_height ? $max_height / $orig_height : 1; + $ratio = min($width_ratio, $height_ratio); + + $width = ceil($orig_width * $ratio); + $height = ceil($orig_height * $ratio); + } + else + { + $width = $orig_width; + $height = $orig_height; + } + + $dst_img = imagecreatetruecolor($width, $height); + + imagecopyresampled($dst_img, $this->Image, 0, 0, 0, 0, $width, $height, $orig_width, $orig_height); + + if($target_filename) + { + imagejpeg($dst_img, $target_filename, $quality); + } + else + { + $this->Image = $dst_img; + } + } + + function SaveImage($quality, $file_name = false) + { + if(!$file_name) + { + $file_name = $this->FileName; + } + imagejpeg($this->Image, $file_name, $quality); + } +} + +?> \ No newline at end of file