Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.99 KB | None | 0 0
  1. <?php
  2. class PracaZObrazkami {
  3.    
  4.    var $image;
  5.    var $image_type;
  6.  
  7.    function Nacitaj($filename) {
  8.       $image_info = getimagesize($filename);
  9.       $this->image_type = $image_info[2];
  10.       if( $this->image_type == IMAGETYPE_JPEG ) {
  11.          $this->image = imagecreatefromjpeg($filename);
  12.       } elseif( $this->image_type == IMAGETYPE_GIF ) {
  13.          $this->image = imagecreatefromgif($filename);
  14.       } elseif( $this->image_type == IMAGETYPE_PNG ) {
  15.          $this->image = imagecreatefrompng($filename);
  16.       }
  17.    }
  18.    function Uloz($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
  19.       if( $image_type == IMAGETYPE_JPEG ) {
  20.          imagejpeg($this->image,$filename,$compression);
  21.       } elseif( $image_type == IMAGETYPE_GIF ) {
  22.          imagegif($this->image,$filename);        
  23.       } elseif( $image_type == IMAGETYPE_PNG ) {
  24.          imagepng($this->image,$filename);
  25.       }  
  26.       if( $permissions != null) {
  27.          chmod($filename,$permissions);
  28.       }
  29.    }
  30.    function ZistiWidth() {
  31.       return imagesx($this->image);
  32.    }
  33.    function ZistiHeight() {
  34.       return imagesy($this->image);
  35.    }
  36.    function ZmenVelkostHeight($height) {
  37.       $ratio = $height / $this->ZistiHeight();
  38.       $width = $this->ZistiWidth() * $ratio;
  39.       $this->resize($width,$height);
  40.    }
  41.    function ZmenVelkostWidth($width) {
  42.       $ratio = $width / $this->ZistiWidth();
  43.       $height = $this->ZistiHeight() * $ratio;
  44.       $this->ZmenitVelkost($width,$height);
  45.    }
  46.    function ZmenitVelkostPercentualne($scale) {
  47.       $width = $this->ZistiWidth() * $scale/100;
  48.       $height = $this->ZistiHeight() * $scale/100;
  49.       $this->ZmenitVelkost($width,$height);
  50.    }
  51.    function ZmenitVelkost($width,$height) {
  52.       $new_image = imagecreatetruecolor($width, $height);
  53.       imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->ZistiWidth(), $this->ZistiHeight());
  54.       $this->image = $new_image;  
  55.    }    
  56. }
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement