Здравствуйте! Подскажите пожалуйста класс для ресайза jpg картинок.
В инете нарыл пару, но есть проблемка - потеря качества, даже при коефициенте 100.
Заранее благодарен за ответ!
Вот что есть сейчас:
Класс (SimpleImage.php):
PHP:
скопировать код в буфер обмена
<?PHP class SimpleImage { var $image; var $image_type; function load($filename) { $this->image_type = $image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { } elseif( $this->image_type == IMAGETYPE_GIF ) { } elseif( $this->image_type == IMAGETYPE_PNG ) { } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=100, $permissions=null) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image,$filename,$compression); } elseif( $image_type == IMAGETYPE_GIF ) { } elseif( $image_type == IMAGETYPE_PNG ) { } if( $permissions != null) { chmod($filename,$permissions); } } function output($image_type=IMAGETYPE_JPEG) { if( $image_type == IMAGETYPE_JPEG ) { } elseif( $image_type == IMAGETYPE_GIF ) { } elseif( $image_type == IMAGETYPE_PNG ) { } } function getWidth() { } function getHeight() { } function resizeToHeight($height) { $ratio = $height / $this->getHeight(); $width = $this->getWidth() * $ratio; $this->resize($width,$height); } function resizeToWidth($width) { $ratio = $width / $this->getWidth(); $height = $this->getheight() * $ratio; $this->resize($width,$height); } function resize($width,$height) { imagecopyresampled($new_image, $this->image, 0 , 0 , 0 , 0 , $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } } ?>
Меняю размер так:
PHP:
скопировать код в буфер обмена
$images=rand(1000000 ,9999999 ); $file="../poll/".$images.".jpg"; $file1="../poll/trumbs/t_".$images.".jpg"; include('SimpleImage.php'); $image = new SimpleImage(); $image->load($_FILES['uploaded_image']['tmp_name']); $image->resizeToWidth(800); $image->save($file); $image->resize(175, 135); $image->save($file1);
Еще раз спасибо!!!(Отредактировано автором: 26 Декабря, 2011 - 15:33:02)
|