public function thumb($thumbwidth, $thumbheight) { list($img_w, $img_h) = $this->_imageinfo; if (!$this->_animatedgif && ($img_w >= $thumbwidth || $img_h >= $thumbheight)) { $imagecreatefromfunc = $this->_imagecreatefromfunc; $imagefunc = $this->_imagefunc; list($img_w, $img_h) = $this->_imageinfo; $attach_photo = $imagecreatefromfunc($this->_imagefile); $x_ratio = $thumbwidth / $img_w; $y_ratio = $thumbheight / $img_h; if ($x_ratio * $img_h < $thumbheight) { $thumb['height'] = ceil($x_ratio * $img_h); $thumb['width'] = $thumbwidth; } else { $thumb['width'] = ceil($y_ratio * $img_w); $thumb['height'] = $thumbheight; } $targetfile = $this->_imagefile . '.thumb.jpg'; $cx = $img_w; $cy = $img_h; $thumb_photo = imagecreatetruecolor($thumb['width'], $thumb['height']); imageCopyreSampled($thumb_photo, $attach_photo, 0, 0, 0, 0, $thumb['width'], $thumb['height'], $cx, $cy); clearstatcache(); if ($this->_imageinfo[2] == 2) { $imagefunc($thumb_photo, $targetfile, 80); } else { $imagefunc($thumb_photo, $targetfile); } } }
function Thumb($thumbwidth = "220", $thumbheight = "220", $thumb_ext = ".small.jpg") { $thumbstatus = 1; $imagelib = 0; $thumbquality = 100; if ($thumbstatus && function_exists('imagecreatetruecolor') && function_exists('imagecopyresampled') && function_exists('imagejpeg')) { $imagecreatefromfunc = $this->imagecreatefromfunc; $imagefunc = $thumbstatus == 1 ? 'imagejpeg' : $this->imagefunc; list($img_w, $img_h) = $this->attachinfo; if (!$this->animatedgif && ($img_w >= $thumbwidth || $img_h >= $thumbheight)) { if ($thumbstatus != 3) { $attach_photo = $imagecreatefromfunc($this->targetfile); $x_ratio = $thumbwidth / $img_w; $y_ratio = $thumbheight / $img_h; if ($x_ratio * $img_h < $thumbheight) { $thumb['height'] = ceil($x_ratio * $img_h); $thumb['width'] = $thumbwidth; } else { $thumb['width'] = ceil($y_ratio * $img_w); $thumb['height'] = $thumbheight; } $thumb_ext = is_null($thumb_ext) ? '' : $thumb_ext; $targetfile = $thumbstatus == 1 ? $this->targetfile . $thumb_ext : $this->targetfile; $cx = $img_w; $cy = $img_h; } $thumb_photo = imagecreatetruecolor($thumb['width'], $thumb['height']); imageCopyreSampled($thumb_photo, $attach_photo, 0, 0, 0, 0, $thumb['width'], $thumb['height'], $cx, $cy); clearstatcache(); if ($this->attachinfo['mime'] == 'image/jpeg') { $imagefunc($thumb_photo, $targetfile, $thumbquality); } else { $imagefunc($thumb_photo, $targetfile); } $this->attach['thumb'] = $thumbstatus == 1 || $thumbstatus == 3 ? 1 : 0; } else { copy($this->srcfile, $this->targetfile . $thumb_ext); } } $this->attach['size'] = filesize($this->targetfile); }
function Thumb_GD($thumbwidth, $thumbheight) { if (function_exists('imagecreatetruecolor') && function_exists('imagecopyresampled') && function_exists('imagejpeg')) { $imagecreatefromfunc = $this->imagecreatefromfunc; $imagefunc = $this->imagefunc; list($img_w, $img_h) = $this->attachinfo; if (!$this->animatedgif && ($img_w >= $thumbwidth || $img_h >= $thumbheight)) { $attach_photo = $imagecreatefromfunc($this->srcfile); $imgratio = $img_w / $img_h; $thumbratio = $thumbwidth / $thumbheight; if ($imgratio >= 1 && $imgratio >= $thumbratio || $imgratio < 1 && $imgratio > $thumbratio) { $cuty = $img_h; $cutx = $cuty * $thumbratio; } elseif ($imgratio >= 1 && $imgratio <= $thumbratio || $imgratio < 1 && $imgratio < $thumbratio) { $cutx = $img_w; $cuty = $cutx / $thumbratio; } $dst_photo = imagecreatetruecolor($cutx, $cuty); imageCopyMerge($dst_photo, $attach_photo, 0, 0, 0, 0, $cutx, $cuty, 100); $thumb['width'] = $thumbwidth; $thumb['height'] = $thumbheight; $targetfile = $this->targetfile; $thumb_photo = imagecreatetruecolor($thumb['width'], $thumb['height']); imageCopyreSampled($thumb_photo, $dst_photo, 0, 0, 0, 0, $thumb['width'], $thumb['height'], $cutx, $cuty); clearstatcache(); if ($this->attachinfo['mime'] == 'image/jpeg') { $imagefunc($thumb_photo, $targetfile, 100); } else { $imagefunc($thumb_photo, $targetfile); } return TRUE; } } return FALSE; }
function Thumb_GD($thumbwidth, $thumbheight, $preview = 0) { global $thumbstatus, $thumbquality; if ($thumbstatus && function_exists('imagecreatetruecolor') && function_exists('imagecopyresampled') && function_exists('imagejpeg')) { $imagecreatefromfunc = $this->imagecreatefromfunc; $imagefunc = $thumbstatus == 1 ? 'imagejpeg' : $this->imagefunc; list($img_w, $img_h) = $this->attachinfo; if (!$this->animatedgif && ($img_w >= $thumbwidth || $img_h >= $thumbheight)) { if ($thumbstatus != 3) { $attach_photo = $imagecreatefromfunc($this->targetfile); $x_ratio = $thumbwidth / $img_w; $y_ratio = $thumbheight / $img_h; if ($x_ratio * $img_h < $thumbheight) { $thumb['height'] = ceil($x_ratio * $img_h); $thumb['width'] = $thumbwidth; } else { $thumb['width'] = ceil($y_ratio * $img_w); $thumb['height'] = $thumbheight; } $targetfile = !$preview ? $thumbstatus == 1 ? $this->targetfile . '.thumb.jpg' : $this->targetfile : DISCUZ_ROOT . './forumdata/watermark_temp.jpg'; $cx = $img_w; $cy = $img_h; } else { $attach_photo = $imagecreatefromfunc($this->targetfile); $imgratio = $img_w / $img_h; $thumbratio = $thumbwidth / $thumbheight; if ($imgratio >= 1 && $imgratio >= $thumbratio || $imgratio < 1 && $imgratio > $thumbratio) { $cuty = $img_h; $cutx = $cuty * $thumbratio; } elseif ($imgratio >= 1 && $imgratio <= $thumbratio || $imgratio < 1 && $imgratio < $thumbratio) { $cutx = $img_w; $cuty = $cutx / $thumbratio; } $dst_photo = imagecreatetruecolor($cutx, $cuty); imageCopyMerge($dst_photo, $attach_photo, 0, 0, 0, 0, $cutx, $cuty, 100); $thumb['width'] = $thumbwidth; $thumb['height'] = $thumbheight; $targetfile = !$preview ? $this->targetfile . '.thumb.jpg' : DISCUZ_ROOT . './forumdata/watermark_temp.jpg'; $cx = $cutx; $cy = $cuty; } $thumb_photo = imagecreatetruecolor($thumb['width'], $thumb['height']); imageCopyreSampled($thumb_photo, $attach_photo, 0, 0, 0, 0, $thumb['width'], $thumb['height'], $cx, $cy); clearstatcache(); if ($this->attachinfo['mime'] == 'image/jpeg') { $imagefunc($thumb_photo, $targetfile, $thumbquality); } else { $imagefunc($thumb_photo, $targetfile); } $this->attach['thumb'] = $thumbstatus == 1 || $thumbstatus == 3 ? 1 : 0; } } }
function Thumb_GD($thumbwidth, $thumbheight, $preview = 0) { global $thumbstatus; if ($thumbstatus && function_exists('imagecreatetruecolor') && function_exists('imagecopyresampled') && function_exists('imagejpeg')) { $imagecreatefromfunc = $this->imagecreatefromfunc; $imagefunc = $thumbstatus == 1 ? 'imagejpeg' : $this->imagefunc; list($img_w, $img_h) = $this->attachinfo; if (!$this->animatedgif && ($img_w >= $thumbwidth || $img_h >= $thumbheight)) { $attach_photo = $imagecreatefromfunc($this->targetfile); $x_ratio = $thumbwidth / $img_w; $y_ratio = $thumbheight / $img_h; if ($x_ratio * $img_h < $thumbheight) { $thumb['height'] = ceil($x_ratio * $img_h); $thumb['width'] = $thumbwidth; } else { $thumb['width'] = ceil($y_ratio * $img_w); $thumb['height'] = $thumbheight; } $targetfile = !$preview ? $thumbstatus == 1 ? $this->targetfile . '.thumb.jpg' : $this->targetfile : DISCUZ_ROOT . './forumdata/watermark_temp.jpg'; $thumb_photo = imagecreatetruecolor($thumb['width'], $thumb['height']); imageCopyreSampled($thumb_photo, $attach_photo, 0, 0, 0, 0, $thumb['width'], $thumb['height'], $img_w, $img_h); if ($this->attachinfo['mime'] == 'image/jpeg') { $imagefunc($thumb_photo, $targetfile, 100); } else { $imagefunc($thumb_photo, $targetfile); } $this->attach['thumb'] = $thumbstatus == 1 ? 1 : 0; } } }
function Thumb_GD($targetfile, $thumbwidth, $thumbheight) { $attachinfo = @getimagesize($targetfile); list($img_w, $img_h) = $attachinfo; header('Content-type: ' . $attachinfo['mime']); if ($img_w >= $thumbwidth || $img_h >= $thumbheight) { if (function_exists('imagecreatetruecolor') && function_exists('imagecopyresampled') && function_exists('imagejpeg')) { switch ($attachinfo['mime']) { case 'image/jpeg': $imagecreatefromfunc = function_exists('imagecreatefromjpeg') ? 'imagecreatefromjpeg' : ''; $imagefunc = function_exists('imagejpeg') ? 'imagejpeg' : ''; break; case 'image/gif': $imagecreatefromfunc = function_exists('imagecreatefromgif') ? 'imagecreatefromgif' : ''; $imagefunc = function_exists('imagegif') ? 'imagegif' : ''; break; case 'image/png': $imagecreatefromfunc = function_exists('imagecreatefrompng') ? 'imagecreatefrompng' : ''; $imagefunc = function_exists('imagepng') ? 'imagepng' : ''; break; } $imagefunc = $thumbstatus == 1 ? 'imagejpeg' : $imagefunc; $attach_photo = $imagecreatefromfunc($targetfile); $x_ratio = $thumbwidth / $img_w; $y_ratio = $thumbheight / $img_h; if ($x_ratio * $img_h < $thumbheight) { $thumb['height'] = ceil($x_ratio * $img_h); $thumb['width'] = $thumbwidth; } else { $thumb['width'] = ceil($y_ratio * $img_w); $thumb['height'] = $thumbheight; } $cx = $img_w; $cy = $img_h; $thumb_photo = imagecreatetruecolor($thumb['width'], $thumb['height']); imageCopyreSampled($thumb_photo, $attach_photo, 0, 0, 0, 0, $thumb['width'], $thumb['height'], $cx, $cy); clearstatcache(); if ($attachinfo['mime'] == 'image/jpeg') { $imagefunc($thumb_photo, null, 90); } else { $imagefunc($thumb_photo); } } } else { readfile($targetfile); exit; } }
/** * 根据指定大小生成缩略图(使用GD库) * * @param int $thumbWidth: 指定缩略图的宽 * @param int $thumbHeight: 指定缩略图的高 * @return void */ function thumb($thumbWidth = '', $thumbHeight = '', $targetFile = '', $upFile = '') { if ($targetFile) { $this->image($targetFile); } $thumbWidth = $thumbWidth ? $thumbWidth : $this->thumbWidth; $thumbHeight = $thumbHeight ? $thumbHeight : $this->thumbHeight; if ($this->thumbStatus && function_exists('imagecreatetruecolor') && function_exists('imagecopyresampled') && function_exists('imagejpeg') && $this->imageCreateFromFunc && $this->imageFunc) { $imageCreateFromFunc = $this->imageCreateFromFunc; $imageFunc = $this->thumbStatus == 1 ? 'imagejpeg' : $this->imageFunc; list($imgWidth, $imgHeight) = $this->targetInfo; if (!$this->animatedGif) { //取消缩略图大小在原图大小范围内的限制 by dsk //if(!$this->animatedGif && ($imgWidth >= $thumbWidth || $imgHeight >= $thumbHeight)) { $upFilePhoto = $imageCreateFromFunc($this->targetFile); $XRation = $thumbWidth / $imgWidth; $YRation = $thumbHeight / $imgHeight; if ($XRation * $imgHeight < $thumbHeight) { $thumb['height'] = ceil($XRation * $imgHeight); $thumb['width'] = $thumbWidth; } else { $thumb['width'] = ceil($YRation * $imgWidth); $thumb['height'] = $thumbHeight; } $this->thumbDir && $this->getSubDir(); $thumbDir = $this->thumbDir ? $this->thumbDir : pathinfo($this->targetFile, PATHINFO_DIRNAME) . '/'; $thumbName = $this->thumbName ? $this->thumbName == 'random' ? date("YmdHis") . $this->random(10, 1) . '.jpg' : $this->thumbName : basename($this->targetFile) . '.thumb.jpg'; $targetFile = $this->thumbStatus == 1 ? $thumbDir . $thumbName : $this->targetFile; $thumbPhoto = imagecreatetruecolor($thumb['width'], $thumb['height']); imageCopyreSampled($thumbPhoto, $upFilePhoto, 0, 0, 0, 0, $thumb['width'], $thumb['height'], $imgWidth, $imgHeight); clearstatcache(); if ($this->targetInfo['mime'] == 'image/jpeg') { $imageFunc($thumbPhoto, $targetFile, $this->thumbQuality); } else { $imageFunc($thumbPhoto, $targetFile); } $this->upFile['thumbDir'] = str_replace(MOOPHP_ROOT . '/', '', $thumbDir); $this->upFile['thumbName'] = $thumbName; $this->upFile['thumbWidth'] = $thumb['width']; $this->upFile['thumbHeight'] = $thumb['height']; $this->upFile['thumb'] = $this->thumbStatus == 1 ? 1 : 0; } } else { return; } if ($this->thumbStatus == 2 && $this->waterMarkStatus) { $this->image($this->targetFile, $this->upFile); $this->upFile['thumb'] = 2; $this->upFile['thumbDir'] = pathinfo($this->targetFile, PATHINFO_DIRNAME) . '/'; $this->upFile['thumbName'] = basename($this->targetFile); } $this->upFile['size'] = filesize($this->targetFile); }