Advertisement
Guest User

Image class

a guest
Jul 3rd, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.33 KB | None | 0 0
  1. <?php
  2.  
  3. class Imagedetail {
  4.  
  5.     private $width;
  6.     private $height;
  7.     private $path;
  8.  
  9.     public function __construct($width, $height, $path) {
  10.         $this->width = $width;
  11.         $this->height = $height;
  12.         $this->path = $path;
  13.     }
  14.  
  15.     public function setWidth($width) {
  16.         $this->width = $width;
  17.     }
  18.  
  19.     public function getWidth() {
  20.         return $this->width;
  21.     }
  22.  
  23.     public function setHeight($height) {
  24.         $this->height = $height;
  25.     }
  26.  
  27.     public function getHeight() {
  28.         return $this->height;
  29.     }
  30.  
  31.     public function setPath($path) {
  32.         $this->path = $path;
  33.     }
  34.  
  35.     public function getPath() {
  36.         return $this->path;
  37.     }
  38.  
  39. }
  40.  
  41. class Imageserver {
  42.  
  43.     private $image;
  44.     private $image_type;
  45.  
  46.     function load($filename) {
  47.  
  48.         $image_info = getimagesize($filename);
  49.  
  50.         $this->image_type = $image_info[2];
  51.         if ($this->image_type == IMAGETYPE_JPEG) {
  52.             $this->image = imagecreatefromjpeg($filename);
  53.         } elseif ($this->image_type == IMAGETYPE_GIF) {
  54.  
  55.             $this->image = imagecreatefromgif($filename);
  56.         } elseif ($this->image_type == IMAGETYPE_PNG) {
  57.  
  58.             $this->image = imagecreatefrompng($filename);
  59.         }
  60.     }
  61.  
  62.     function save($originalFile, $filename, $permissions) {
  63.         if ($permissions != null) {
  64.             chmod($originalFile, $permissions);
  65.         }
  66.  
  67.         if ($this->image_type == IMAGETYPE_JPEG) {
  68.  
  69.             imagejpeg($this->image, $filename, 75);
  70.         } elseif ($this->image_type == IMAGETYPE_GIF) {
  71.             imagegif($this->image, $filename);
  72.         } elseif ($this->image_type == IMAGETYPE_PNG) {
  73.             imagepng($this->image, $filename);
  74.         }
  75.     }
  76.  
  77.     function output($image_type) {
  78.  
  79.         if ($image_type == IMAGETYPE_JPEG) {
  80.             imagejpeg($this->image);
  81.         } elseif ($image_type == IMAGETYPE_GIF) {
  82.             imagegif($this->image);
  83.         } elseif ($image_type == IMAGETYPE_PNG) {
  84.             imagepng($this->image);
  85.         }
  86.     }
  87.  
  88.     function getWidth() {
  89.  
  90.         return imagesx($this->image);
  91.     }
  92.  
  93.     function getHeight() {
  94.  
  95.         return imagesy($this->image);
  96.     }
  97.  
  98.     function resizeToHeight($height) {
  99.  
  100.         $ratio = $height / $this->getHeight();
  101.         $width = $this->getWidth() * $ratio;
  102.         $this->resize($width, $height);
  103.     }
  104.  
  105.     function resizeToWidth($width) {
  106.         $ratio = $width / $this->getWidth();
  107.         $height = $this->getheight() * $ratio;
  108.         $this->resize($width, $height);
  109.     }
  110.  
  111.     function scale($scale) {
  112.         $width = $this->getWidth() * $scale / 100;
  113.         $height = $this->getheight() * $scale / 100;
  114.         $this->resize($width, $height);
  115.     }
  116.  
  117.     function resize($width, $height) {
  118.         $new_image = imagecreatetruecolor($width, $height);
  119.         imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
  120.         $this->image = $new_image;
  121.     }
  122.  
  123.     function setImageType($image_type) {
  124.         $this->image_type = $image_type;
  125.     }
  126.  
  127.     function getImageType() {
  128.         return $this->image_type;
  129.     }
  130.  
  131.     function setImage($image) {
  132.         $this->image = $image;
  133.     }
  134.  
  135.     function getImage() {
  136.         return $this->image;
  137.     }
  138.  
  139. }
  140. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement