Esempio n. 1
0
 function createcropedavatar()
 {
     //require_once WRA_Path."/modules/cropcanvas/class.cropcanvas.php";//обрезка изображений
     //require_once WRA_Path."/modules/cropcanvas/class.cropinterface.php";//обрезка изображений
     if ($this->error != "") {
         return;
     }
     $this->tmbfilename = "tmb_" . $this->filename;
     $this->getimageinfo();
     if ($this->imageheight >= $this->imagewidth) {
         $image_info = getimagesize($this->uploaddir . $this->filename);
         $image_type = $image_info[2];
         $image = "";
         if ($image_type == IMAGETYPE_JPEG) {
             $image = imagecreatefromjpeg($this->uploaddir . $this->filename);
         } elseif ($this->image_type == IMAGETYPE_GIF) {
             $image = imagecreatefromgif($this->uploaddir . $this->filename);
         } elseif ($this->image_type == IMAGETYPE_PNG) {
             $image = imagecreatefrompng($this->uploaddir . $this->filename);
         }
         $newheight = $this->imageheight / $this->imagewidth * $this->tmbwidth;
         $new_image = imagecreatetruecolor($this->tmbwidth, $newheight);
         imagecopyresampled($new_image, $image, 0, 0, 0, 0, $this->tmbwidth, $newheight, $this->imagewidth, $this->imageheight);
         $image = $new_image;
         $cc = new cropImage();
         $cc->setImage($new_image, $this->tmbwidth, $newheight);
         $cc->createThumb($this->tmbwidth);
         $image = $cc->myImage;
         if ($image_type == IMAGETYPE_JPEG) {
             imagejpeg($image, $this->uploaddir . $this->tmbfilename, $this->tmbcompr);
         } elseif ($image_type == IMAGETYPE_GIF) {
             imagegif($image, $this->uploaddir . $this->tmbfilename);
         } elseif ($image_type == IMAGETYPE_PNG) {
             imagepng($image, $this->uploaddir . $this->tmbfilename);
         }
     } elseif ($this->imageheight < $this->imagewidth) {
         $image_info = getimagesize($this->uploaddir . $this->filename);
         $image_type = $image_info[2];
         $image = "";
         if ($image_type == IMAGETYPE_JPEG) {
             $image = imagecreatefromjpeg($this->uploaddir . $this->filename);
         } elseif ($this->image_type == IMAGETYPE_GIF) {
             $image = imagecreatefromgif($this->uploaddir . $this->filename);
         } elseif ($this->image_type == IMAGETYPE_PNG) {
             $image = imagecreatefrompng($this->uploaddir . $this->filename);
         }
         $newheight = $this->imagewidth / $this->imageheight * $this->tmbwidth;
         $new_image = imagecreatetruecolor($newheight, $this->tmbwidth);
         imagecopyresampled($new_image, $image, 0, 0, 0, 0, $newheight, $this->tmbwidth, $this->imagewidth, $this->imageheight);
         $image = $new_image;
         $cc = new cropImage();
         $cc->setImage($new_image, $newheight, $this->tmbwidth);
         $cc->createThumb($this->tmbwidth);
         $image = $cc->myImage;
         if ($image_type == IMAGETYPE_JPEG) {
             imagejpeg($image, $this->uploaddir . $this->tmbfilename, $this->tmbcompr);
         } elseif ($image_type == IMAGETYPE_GIF) {
             imagegif($image, $this->uploaddir . $this->tmbfilename);
         } elseif ($image_type == IMAGETYPE_PNG) {
             imagepng($image, $this->uploaddir . $this->tmbfilename);
         }
     } else {
         copy($this->uploaddir . $this->filename, $this->uploaddir . $this->tmbfilename);
     }
 }