Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: Resize картинок jpg
Форумы портала PHP.SU » » Графика в PHP » Resize картинок jpg

Страниц (1): [1]
 

1. ensik - 26 Декабря, 2011 - 15:30:07 - перейти к сообщению
Здравствуйте! Подскажите пожалуйста класс для ресайза jpg картинок.
В инете нарыл пару, но есть проблемка - потеря качества, даже при коефициенте 100.

Заранее благодарен за ответ!

Вот что есть сейчас:

Класс (SimpleImage.php):
PHP:
скопировать код в буфер обмена
  1. <?PHP
  2.  
  3. class SimpleImage {
  4.  
  5.    var $image;
  6.    var $image_type;
  7.  
  8.    function load($filename) {
  9.  
  10.       $image_info = getimagesize($filename);
  11.       $this->image_type = $image_info[2];
  12.       if( $this->image_type == IMAGETYPE_JPEG ) {
  13.  
  14.          $this->image = imagecreatefromjpeg($filename);
  15.       } elseif( $this->image_type == IMAGETYPE_GIF ) {
  16.  
  17.          $this->image = imagecreatefromgif($filename);
  18.       } elseif( $this->image_type == IMAGETYPE_PNG ) {
  19.  
  20.          $this->image = imagecreatefrompng($filename);
  21.       }
  22.    }
  23.    function save($filename, $image_type=IMAGETYPE_JPEG, $compression=100, $permissions=null) {
  24.  
  25.       if( $image_type == IMAGETYPE_JPEG ) {
  26.          imagejpeg($this->image,$filename,$compression);
  27.       } elseif( $image_type == IMAGETYPE_GIF ) {
  28.  
  29.          imagegif($this->image,$filename);
  30.       } elseif( $image_type == IMAGETYPE_PNG ) {
  31.  
  32.          imagepng($this->image,$filename);
  33.       }
  34.       if( $permissions != null) {
  35.  
  36.          chmod($filename,$permissions);
  37.       }
  38.    }
  39.    function output($image_type=IMAGETYPE_JPEG) {
  40.  
  41.       if( $image_type == IMAGETYPE_JPEG ) {
  42.          imagejpeg($this->image);
  43.       } elseif( $image_type == IMAGETYPE_GIF ) {
  44.  
  45.          imagegif($this->image);
  46.       } elseif( $image_type == IMAGETYPE_PNG ) {
  47.  
  48.          imagepng($this->image);
  49.       }
  50.    }
  51.    function getWidth() {
  52.  
  53.       return imagesx($this->image);
  54.    }
  55.    function getHeight() {
  56.  
  57.       return imagesy($this->image);
  58.    }
  59.    function resizeToHeight($height) {
  60.  
  61.       $ratio = $height / $this->getHeight();
  62.       $width = $this->getWidth() * $ratio;
  63.       $this->resize($width,$height);
  64.    }
  65.  
  66.    function resizeToWidth($width) {
  67.       $ratio = $width / $this->getWidth();
  68.       $height = $this->getheight() * $ratio;
  69.       $this->resize($width,$height);
  70.    }
  71.  
  72.  
  73.  
  74.    function resize($width,$height) {
  75.       $new_image = imagecreatetruecolor($width, $height);
  76.       imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
  77.       $this->image = $new_image;
  78.    }      
  79.  
  80. }
  81. ?>


Меняю размер так:
PHP:
скопировать код в буфер обмена
  1.  
  2. $images=rand(1000000,9999999);
  3.  
  4. $file="../poll/".$images.".jpg";
  5. $file1="../poll/trumbs/t_".$images.".jpg";
  6.  
  7.       include('SimpleImage.php');
  8.       $image = new SimpleImage();
  9.       $image->load($_FILES['uploaded_image']['tmp_name']);
  10.       $image->resizeToWidth(800);
  11.       $image->save($file);
  12.       $image->resize(175, 135);
  13.       $image->save($file1);  


Еще раз спасибо!!!
2. Мелкий - 26 Декабря, 2011 - 15:43:58 - перейти к сообщению
Попробуйте imagick.
http://nl2.php.net/manual/en/class.imagick.php
3. ensik - 26 Декабря, 2011 - 16:00:25 - перейти к сообщению
Мелкий пишет:
Попробуйте imagick.
http://nl2.php.net/manual/en/class.imagick.php


Спасибо, буду пробовать!

 

Powered by ExBB FM 1.0 RC1