size.php
<?php include('resize.php'); $klasa=new ResizeImg('lay.png',300); ?>
resize.php - klasa
<?php class ResizeImg{ private $url; private $mime_type; private $width; private $height; private $oldwidth; private $oldheight; private $root; private $new; public function __construct($url,$width) { $this->url=$url; $this->mime_type=$this->get_mime(); $this->width=$width; $this->height=$this->set_height(); $this->oldwidth=$this->get_width(); $this->oldheight=$this->get_height(); } //wykonujemy wszystkie operacje public function __destruct() { $this->open(); $this->create(); $this->copy(); } //pobieramy type-mime private function get_mime() { return $mime['mime']; } //pobieramy aktualna szerokosc private function get_width() { return $width[0]; } //pobieramy aktualna wysokosc private function get_height() { return $height[1]; } //ustalamy wysokosc private function set_height() { $height=($this->oldheight*$this->width)/$this->oldwidth; return $height; } //otwieramy aktualny obraz private function open() { switch($this->mime_type) { case 'image/jpeg' : $root=imagecreatefromjpeg($this->url); break; case 'image/gif' : $root=imagecreatefromgif($this->url); break; case 'image/png' : $root=imagecreatefrompng($this->url); break; } $this->root=$root; } //tworzymy nowy obraz private function create() { $this->new=imagecreatetruecolor($this->width,$this->height); } //tworzymy kopie obrazka { imagecopyresampled($this->new, $this->root, 0, 0, 0, 0, $this->width, $this->height, $this->oldwidth, $this->oldheight); return imagejpeg($this->new); } } ?>
Podane zdjęcie znajduje się na serwerze.
http://artisan-programista.xaa.pl/size.php - przykład złego działania