当前位置: 首页>>代码示例>>PHP>>正文


PHP ImageCopyResized函数代码示例

本文整理汇总了PHP中ImageCopyResized函数的典型用法代码示例。如果您正苦于以下问题:PHP ImageCopyResized函数的具体用法?PHP ImageCopyResized怎么用?PHP ImageCopyResized使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ImageCopyResized函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ResizeWidthHeight

function ResizeWidthHeight($picture, $smallfile, $rewidth, $reheight)
{
    $picsize = getimagesize($picture);
    if ($picsize[2] == 1) {
        //@header("Content-Type: imgage/gif");
        $dstimg = ImageCreatetruecolor($rewidth, $reheight);
        $srcimg = @ImageCreateFromGIF($picture);
        ImageCopyResized($dstimg, $srcimg, 0, 0, 0, 0, $rewidth, $reheight, ImageSX($srcimg), ImageSY($srcimg));
        Imagegif($dstimg, $smallfile, 100);
    } elseif ($picsize[2] == 2) {
        //@header("Content-Type: images/jpeg");
        $dstimg = ImageCreatetruecolor($rewidth, $reheight);
        $srcimg = ImageCreateFromJPEG($picture);
        imagecopyresampled($dstimg, $srcimg, 0, 0, 0, 0, $rewidth, $reheight, ImageSX($srcimg), ImageSY($srcimg));
        Imagejpeg($dstimg, $smallfile, 100);
    } elseif ($picsize[2] == 3) {
        //@header("Content-Type: images/png");
        $srcimg = ImageCreateFromPNG($picture);
        $dstimg = imagecreate($rewidth, $reheight);
        $black = imagecolorallocate($dstimg, 0x0, 0x0, 0x0);
        $white = imagecolorallocate($dstimg, 0xff, 0xff, 0xff);
        $magenta = imagecolorallocate($dstimg, 0xff, 0x0, 0xff);
        imagecolortransparent($dstimg, $black);
        imagecopyresampled($dstimg, $srcimg, 0, 0, 0, 0, $rewidth, $reheight, ImageSX($srcimg), ImageSY($srcimg));
        Imagepng($dstimg, $smallfile, 0);
    }
    @ImageDestroy($dstimg);
    @ImageDestroy($srcimg);
}
开发者ID:eosliebe,项目名称:rb,代码行数:29,代码来源:thumb.func.php

示例2: image

 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $wh = false)
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = ImageCreate($imgW, $imgH);
     $col[0] = ImageColorAllocate($base_image, 255, 255, 255);
     $col[1] = ImageColorAllocate($base_image, 0, 0, 0);
     imagefill($base_image, 0, 0, $col[0]);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $www = $imgW * $pixelPerPoint;
     $hhh = $imgH * $pixelPerPoint;
     if (is_array($wh)) {
         $www = $wh[0];
         $hhh = $wh[1];
     }
     $target_image = ImageCreate($www, $hhh);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $www, $hhh, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
开发者ID:codingoneapp,项目名称:codingone,代码行数:28,代码来源:qrimage.php

示例3: resizeImg

function resizeImg($origPath, $mW, $mH)
{
    // Read the size
    $rst['size'] = GetImageSize($origPath);
    $w = $rst['size'][0];
    $h = $rst['size'][1];
    // Proportionally resize the image to the max sizes specified above
    $xRatio = $mW / $w;
    $yRatio = $mH / $h;
    if ($w <= $mW && $h <= $mH) {
        $tnW = $w;
        $tnH = $h;
    } elseif ($xRatio * $h < $mH) {
        $tnH = ceil($xRatio * $h);
        $tnW = $mW;
    } else {
        $tnW = ceil($yRatio * $w);
        $tnH = $mH;
    }
    // Create the new image!
    if ($rst['size']['mime'] == 'image/jpg' || $rst['size']['mime'] == 'image/jpeg') {
        $rst['src'] = imagecreatefromjpeg($origPath);
        $rst['dst'] = ImageCreateTrueColor($tnW, $tnH);
        $rst['resize'] = ImageCopyResized($rst['dst'], $rst['src'], 0, 0, 0, 0, $tnW, $tnH, $w, $h);
        $rst['imgMod'] = imagejpeg($rst['dst'], $origPath, 100);
    } else {
        $rst['note'] = 'Error with file type!';
        return false;
    }
    return $rst;
}
开发者ID:badwolfgirl,项目名称:Reporting-System,代码行数:31,代码来源:uploadify.php

示例4: image

 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $color = array())
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = ImageCreate($imgW, $imgH);
     $col[0] = ImageColorAllocate($base_image, 255, 255, 255);
     if ($color) {
         $col[1] = ImageColorAllocate($base_image, $color[0], $color[1], $color[2]);
     } else {
         $col[1] = ImageColorAllocate($base_image, 0, 0, 0);
     }
     imagefill($base_image, 0, 0, $col[0]);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
开发者ID:barricade86,项目名称:raui,代码行数:26,代码来源:qrimage.php

示例5: resize

 function resize($newX = false, $newY = false)
 {
     if ($this->img) {
         $X = ImageSX($this->img);
         $Y = ImageSY($this->img);
         $newX = $this->_convert($newX, $X);
         $newY = $this->_convert($newY, $Y);
         if (!$newX && !$newY) {
             $newX = $X;
             $newY = $Y;
         }
         if (!$newX) {
             $newX = round($X / ($Y / $newY));
         }
         if (!$newY) {
             $newY = round($Y / ($X / $newX));
         }
         if (!($newimg = ImageCreateTruecolor($newX, $newY))) {
             $newimg = ImageCreate($newX, $newY);
         }
         if (!ImageCopyResampled($newimg, $this->img, 0, 0, 0, 0, $newX, $newY, $X, $Y)) {
             ImageCopyResized($newimg, $this->img, 0, 0, 0, 0, $newX, $newY, $X, $Y);
         }
         $this->img = $newimg;
         return true;
     } else {
         return false;
     }
 }
开发者ID:BerlusGmbH,项目名称:Berlussimo,代码行数:29,代码来源:class_thumbs.php

示例6: image

 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xffffff, $fore_color = 0x0)
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = ImageCreate($imgW, $imgH);
     // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
     $r1 = round(($fore_color & 0xff0000) >> 16, 5);
     $b1 = round(($fore_color & 0xff00) >> 8, 5);
     $g1 = round($fore_color & 0xff, 5);
     // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
     $r2 = round(($back_color & 0xff0000) >> 16, 5);
     $b2 = round(($back_color & 0xff00) >> 8, 5);
     $g2 = round($back_color & 0xff, 5);
     $col[0] = ImageColorAllocate($base_image, $r2, $b2, $g2);
     $col[1] = ImageColorAllocate($base_image, $r1, $b1, $g1);
     imagefill($base_image, 0, 0, $col[0]);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
开发者ID:RKathees,项目名称:is-connectors,代码行数:30,代码来源:qrimage.php

示例7: image

 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = imagecreatetruecolor($imgW, $imgH);
     $col[0] = ImageColorAllocate($base_image, 255, 0, 255);
     $col[1] = ImageColorAllocate($base_image, 0, 0, 0);
     imagecolortransparent($base_image, $col[0]);
     imagealphablending($base_image, true);
     imagesavealpha($base_image, true);
     //        imagefill($base_image, 0, 0, $col[0]);
     imagefill($base_image, 0, 0, 0x7fff0000);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
开发者ID:aplitax,项目名称:PHPQRCode,代码行数:26,代码来源:QRimage.php

示例8: ImageResize

function ImageResize($srcFile, $toW, $toH, $toFile = "")
{
    if ($toFile == "") {
        $toFile = $srcFile;
    }
    $info = "";
    $data = GetImageSize($srcFile, $info);
    switch ($data[2]) {
        case 1:
            if (!function_exists("imagecreatefromgif")) {
                echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!<a href='javascript:go(-1);'>返回</a>";
                exit;
            }
            $im = ImageCreateFromGIF($srcFile);
            break;
        case 2:
            if (!function_exists("imagecreatefromjpeg")) {
                echo "你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!<a href='javascript:go(-1);'>返回</a>";
                exit;
            }
            $im = ImageCreateFromJpeg($srcFile);
            break;
        case 3:
            $im = ImageCreateFromPNG($srcFile);
            break;
    }
    $srcW = ImageSX($im);
    $srcH = ImageSY($im);
    $toWH = $toW / $toH;
    $srcWH = $srcW / $srcH;
    if ($toWH <= $srcWH) {
        $ftoW = $toW;
        $ftoH = $ftoW * ($srcH / $srcW);
    } else {
        $ftoH = $toH;
        $ftoW = $ftoH * ($srcW / $srcH);
    }
    if ($srcW > $toW || $srcH > $toH) {
        if (function_exists("imagecreatetruecolor")) {
            @($ni = ImageCreateTrueColor($ftoW, $ftoH));
            if ($ni) {
                ImageCopyResampled($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
            } else {
                $ni = ImageCreate($ftoW, $ftoH);
                ImageCopyResized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
            }
        } else {
            $ni = ImageCreate($ftoW, $ftoH);
            ImageCopyResized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
        }
        if (function_exists('imagejpeg')) {
            ImageJpeg($ni, $toFile);
        } else {
            ImagePNG($ni, $toFile);
        }
        ImageDestroy($ni);
    }
    ImageDestroy($im);
}
开发者ID:chaobj001,项目名称:tt,代码行数:59,代码来源:PHP生成缩略图.php

示例9: twMachThumbnail

function twMachThumbnail($serverPfad, $datei, $breiteThumb, $prefix)
{
    // Bild-Datei (mit Pfad)
    $bildDatei = $serverPfad . $datei;
    // wenn dieses Bild nich gefunden wurde: Abbruch
    if (!file_exists($bildDatei)) {
        return false;
    }
    // wenn dieses Bild schon ein Thumbnail ist: Abbruch
    if (substr($datei, 0, strlen($prefix)) == $prefix) {
        //echo $datei. "<br />";
        //echo strlen($prefix). "<br />";
        //echo $prefix. "<br />";
        //echo substr($datei, strlen($prefix)). "<br />";
        //echo "-----<br />";
        return false;
    }
    // Bilddaten zu dieser Bild-Datei
    $bilddaten = getimagesize($bildDatei);
    $imgOrigBreite = $bilddaten[0];
    $imgOrigHoehe = $bilddaten[1];
    $imgOrigTyp = $bilddaten[2];
    // (1=GIF, 2=JPG, 3=PNG, 4=SWF)
    if ($imgOrigBreite < $breiteThumb) {
        $breiteThumb = $imgOrigBreite;
    }
    $Skalierungsfaktor = $imgOrigBreite / $breiteThumb;
    $thumbHoehe = intval($imgOrigHoehe / $Skalierungsfaktor);
    // wenn es ein gif-Bild ist
    if ($imgOrigTyp == 1) {
        $Originalgrafik = ImageCreateFromGIF($bildDatei);
        $Thumbnailgrafik = ImageCreateTrueColor($breiteThumb, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $breiteThumb, $thumbHoehe, $imgOrigBreite, $imgOrigHoehe);
        ImageGIF($Thumbnailgrafik, $serverPfad . $prefix . $datei, 100);
    } elseif ($imgOrigTyp == 2) {
        $Originalgrafik = ImageCreateFromJPEG($bildDatei);
        $Thumbnailgrafik = ImageCreateTrueColor($breiteThumb, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $breiteThumb, $thumbHoehe, $imgOrigBreite, $imgOrigHoehe);
        ///ImageJPEG($Thumbnailgrafik, $pfad."thumb_".$bild);
        ImageJPEG($Thumbnailgrafik, $serverPfad . $prefix . $datei, 100);
    } elseif ($imgOrigTyp == 3) {
        $Originalgrafik = ImageCreateFromPNG($bildDatei);
        $Thumbnailgrafik = ImageCreateTrueColor($breiteThumb, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $breiteThumb, $thumbHoehe, $imgOrigBreite, $imgOrigHoehe);
        ImagePNG($Thumbnailgrafik, $serverPfad . $prefix . $datei, 100);
    } else {
        return false;
    }
    // Speicher leeren
    if ($Originalgrafik) {
        imagedestroy($Originalgrafik);
    }
    if ($Thumbnailgrafik) {
        imagedestroy($Thumbnailgrafik);
    }
}
开发者ID:BackupTheBerlios,项目名称:shirtbemaler-svn,代码行数:56,代码来源:fkt_image.inc.php

示例10: makeThumb

 function makeThumb($sourFile, $width = 128, $height = 128)
 {
     $imageInfo = $this->getInfo($sourFile);
     $sourFile = $this->sourcePath . $sourFile;
     $newName = substr($imageInfo["name"], 0, strrpos($imageInfo["name"], ".")) . "_thumb.jpg";
     switch ($imageInfo["type"]) {
         case 1:
             //gif
             $img = imagecreatefromgif($sourFile);
             break;
         case 2:
             //jpg
             $img = imagecreatefromjpeg($sourFile);
             break;
         case 3:
             //png
             $img = imagecreatefrompng($sourFile);
             break;
         default:
             return 0;
             break;
     }
     if (!$img) {
         return 0;
     }
     $width = $width > $imageInfo["width"] ? $imageInfo["width"] : $width;
     $height = $height > $imageInfo["height"] ? $imageInfo["height"] : $height;
     $srcW = $imageInfo["width"];
     $srcH = $imageInfo["height"];
     if ($srcW * $width > $srcH * $height) {
         $height = round($srcH * $width / $srcW);
     } else {
         $width = round($srcW * $height / $srcH);
     }
     //*
     if (function_exists("imagecreatetruecolor")) {
         $new = imagecreatetruecolor($width, $height);
         ImageCopyResampled($new, $img, 0, 0, 0, 0, $width, $height, $imageInfo["width"], $imageInfo["height"]);
     } else {
         $new = imagecreate($width, $height);
         ImageCopyResized($new, $img, 0, 0, 0, 0, $width, $height, $imageInfo["width"], $imageInfo["height"]);
     }
     //*/
     if ($this->toFile) {
         if (file_exists($this->thumbPath . $newName)) {
             unlink($this->thumbPath . $newName);
         }
         imagejpeg($new, $this->thumbPath . $newName, 100);
         return $this->thumbPath . $newName;
     } else {
         imagejpeg($new);
     }
     imagedestroy($new);
     imagedestroy($img);
 }
开发者ID:ailingsen,项目名称:pigcms,代码行数:55,代码来源:image.class.php

示例11: _resize

 /**
  * Resize Action
  *
  * For GD 2.01+ the new copyresampled function is used
  * It uses a bicubic interpolation algorithm to get far
  * better result.
  *
  * @param $new_x int  new width
  * @param $new_y int  new height
  * @param mixed $options Optional parameters
  *
  * @return true on success or PEAR Error object on error
  * @see PEAR::isError()
  */
 function _resize($new_x, $new_y, $options = null)
 {
     if ($this->resized === true) {
         return PEAR::raiseError('You have already resized the image without saving it.  Your previous resizing will be overwritten', null, PEAR_ERROR_TRIGGER, E_USER_NOTICE);
     }
     $new_img = ImageCreate($new_x, $new_y);
     ImageCopyResized($new_img, $this->imageHandle, 0, 0, 0, 0, $new_x, $new_y, $this->img_x, $this->img_y);
     $this->old_image = $this->imageHandle;
     $this->imageHandle = $new_img;
     $this->resized = true;
     $this->new_x = $new_x;
     $this->new_y = $new_y;
     return true;
 }
开发者ID:rivetweb,项目名称:old-book-with-active-areas,代码行数:28,代码来源:GD1.php

示例12: thumb

 static function thumb($image, $type = '', $filename = '', $maxWidth = 200, $maxHeight = 50, $interlace = true, $suffix = '_thumb')
 {
     $info = Image::getImageInfo($image);
     if ($info !== false) {
         $srcWidth = $info['width'];
         $srcHeight = $info['height'];
         $pathinfo = pathinfo($image);
         $type = $pathinfo['extension'];
         $type = empty($type) ? $info['type'] : $type;
         $type = strtolower($type);
         $interlace = $interlace ? 1 : 0;
         unset($info);
         $scale = min($maxWidth / $srcWidth, $maxHeight / $srcHeight);
         if ($scale >= 1) {
             $width = $srcWidth;
             $height = $srcHeight;
         } else {
             $width = (int) ($srcWidth * $scale);
             $height = (int) ($srcHeight * $scale);
         }
         $createFun = 'ImageCreateFrom' . ($type == 'jpg' ? 'jpeg' : $type);
         $srcImg = $createFun($image);
         if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
             $thumbImg = imagecreatetruecolor($width, $height);
         } else {
             $thumbImg = imagecreate($width, $height);
         }
         if (function_exists("ImageCopyResampled")) {
             ImageCopyResampled($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
         } else {
             ImageCopyResized($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
         }
         if ('gif' == $type || 'png' == $type) {
             $background_color = imagecolorallocate($thumbImg, 0, 255, 0);
             imagecolortransparent($thumbImg, $background_color);
         }
         if ('jpg' == $type || 'jpeg' == $type) {
             imageinterlace($thumbImg, $interlace);
         }
         $imageFun = 'image' . ($type == 'jpg' ? 'jpeg' : $type);
         $filename = empty($filename) ? substr($image, 0, strrpos($image, '.')) . $suffix . '.' . $type : $filename;
         $imageFun($thumbImg, $filename);
         ImageDestroy($thumbImg);
         ImageDestroy($srcImg);
         return $filename;
     }
     return false;
 }
开发者ID:BGCX067,项目名称:fakebook-svn-to-git,代码行数:48,代码来源:Image.class.php

示例13: resizeImage

function resizeImage($image, $maxHeight)
{
    $width = ImageSx($image);
    $height = ImageSy($image);
    if ($height > $maxHeight) {
        $ratio = $maxHeight / $height;
        $x = $width * $ratio;
        $y = $maxHeight;
    } else {
        $x = $width;
        $y = $height;
    }
    $dst = ImageCreate($x, $y);
    ImageCopyResized($dst, $image, 0, 0, 0, 0, $x, $y, $width, $height);
    return $dst;
}
开发者ID:no2id,项目名称:php-docroot,代码行数:16,代码来源:bannerPic.php

示例14: resizeImage

 /**
  * This function cuts a image created previusly with this class, and receive: width, height and the background color
  * in rgb format. transparent color is the default color.
  * @param int $w
  * @param int $h
  * @param int $red
  * @param int $green
  * @param int $blue
  */
 public function resizeImage($w, $h, $color = null)
 {
     $width = imagesx($this->img);
     $height = imagesy($this->img);
     $proportion = $this->getImageProportion($width, $height, $w, $h);
     $this->newImg = imagecreatetruecolor($w, $h);
     if ($color == null) {
         $transparent = imagecolorallocate($this->newImg, 0, 0, 0);
         imagecolortransparent($this->newImg, $transparent);
     } else {
         $rgb = $this->convertFromHexToRgbColor($color);
         imagecolorallocate($this->newImg, $rgb->red, $rgb->green, $rgb->blue);
     }
     ImageCopyResized($this->newImg, $this->img, $proportion['x'], $proportion['y'], 0, 0, $proportion['newWidth'], $proportion['newHeight'], $width, $height);
     $this->img = $this->newImg;
 }
开发者ID:solutionsCluster,项目名称:silar,代码行数:25,代码来源:ImageManager.php

示例15: smallImg

 /**
  * @todo  缩略图
  * @param string $src  大图路径
  * @param string $to   小图路径
  * @param int $to_w    小图宽度
  * @param int $to_h    小图高度
  * @return boolean|string
  */
 public static function smallImg($src, $to, $to_w, $to_h)
 {
     $data = getimagesize($src);
     //0为宽,1为高,2为类型
     $srcW = $data[0];
     $srcH = $data[1];
     switch ($data[2]) {
         case 1:
             //图片类型,1是GIF图
             $im = @ImageCreateFromGIF($src);
             break;
         case 2:
             //图片类型,2是JPG图
             $im = @imagecreatefromjpeg($src);
             break;
         case 3:
             //图片类型,3是PNG图
             $im = @ImageCreateFromPNG($src);
             break;
     }
     if (empty($im)) {
         return false;
     }
     $to_w = $to_w > $srcW ? $srcW : $to_w;
     $to_h = $to_h > $srcH ? $srcH : $to_h;
     if ($srcW * $to_w > $srcH * $to_h) {
         $to_h = round($srcH * $to_w / $srcW);
     } else {
         $to_w = round($srcW * $to_h / $srcH);
     }
     if (function_exists("imagecreatetruecolor")) {
         $newImg = imagecreatetruecolor($to_w, $to_h);
         ImageCopyResampled($newImg, $im, 0, 0, 0, 0, $to_w, $to_h, $srcW, $srcH);
     } else {
         $newImg = imagecreate($to_w, $to_h);
         ImageCopyResized($newImg, $im, 0, 0, 0, 0, $to_w, $to_h, $srcW, $srcH);
     }
     $todir = dirname($to);
     if (!is_dir($todir)) {
         @mkdir($todir, 0777, true);
     }
     imagejpeg($newImg, $to);
     imagedestroy($newImg);
     imagedestroy($im);
     return $to;
 }
开发者ID:kl0428,项目名称:admin,代码行数:54,代码来源:Helper.php


注:本文中的ImageCopyResized函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。