Вот эта функция путь к файлу - $this->src
| Код | public function img_resize(){
$link_array = explode('.',$this->src); $filetype=$link_array[count($link_array)-1];
if(!file_exists($this->src)){ $size=$this->width; } else $size = getimagesize($this->src);
if ($size === false) return false; // Определяем исходный формат по MIME-информации, предоставленной // функцией getimagesize, и выбираем соответствующую формату // imagecreatefrom-функцию. $format = strtolower(substr($size['mime'], strpos($size['mime'], '/') + 1)); $icfunc = "imagecreatefrom" . $format; if (!function_exists($icfunc)) return false;
if (intval($this->width) == 0) { $new_width = round($size[0]); $new_height = round($size[1]); } else { if($size[0]>=$size[1]) {$ratio = $size[0] / $this->width;} else { $ratio = $size[1]/$this->height;} $new_width = round($size[0] / $ratio); $new_height = round($size[1] / $ratio); $new_left = 0; //$use_x_ratio ? 0 : floor(($$this->width - $new_width) / 2); $new_top = 0; //!$use_x_ratio ? 0 : floor(($height - $new_height) / 2); }
$isrc = $icfunc($this->src); $idest = imagecreatetruecolor($new_width, $new_height);
imagefill($idest, 0, 0, RGB);
imagecopyresampled($idest, $isrc, $new_left, $new_top, 0, 0, $new_width, $new_height, $size[0], $size[1]);
if (!file_exists($this->src)) { $textcolor = imagecolorallocate($idest, 255, 0, 0); // write the string at the top left imagestring($idest, 2, 0, 0, "Not found", $textcolor); } switch ($filetype) { case 'jpg': imagejpeg($idest); break; case 'gif': // константное выражение 2 imagegif($idest); break; } imagedestroy($isrc); imagedestroy($idest); return true; }
|
|