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


PHP imagecopyresampled函数代码示例

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


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

示例1: resizeThumbnailImage

 function resizeThumbnailImage($thumb, $image, $width, $height, $start_width, $start_height, $scale)
 {
     $newImageWidth = ceil($width * $scale);
     $newImageHeight = ceil($height * $scale);
     $newImage = imagecreatetruecolor($newImageWidth, $newImageHeight);
     $ext = strtolower(substr(basename($image), strrpos(basename($image), '.') + 1));
     $source = '';
     if ($ext == 'png') {
         $source = imagecreatefrompng($image);
     } elseif ($ext == 'jpg' || $ext == 'jpeg') {
         $source = imagecreatefromjpeg($image);
     } elseif ($ext == 'gif') {
         $source = imagecreatefromgif($image);
     }
     imagecopyresampled($newImage, $source, 0, 0, $start_width, $start_height, $newImageWidth, $newImageHeight, $width, $height);
     $ext = strtolower(substr(basename($thumb), strrpos(basename($thumb), '.') + 1));
     if ($ext == 'png') {
         $result = imagepng($newImage, $thumb, 0);
     } elseif ($ext == 'jpg' || $ext == 'jpeg') {
         $result = imagejpeg($newImage, $thumb, 90);
     } elseif ($ext == 'gif') {
         $result = imagegif($newImage, $thumb);
     }
     if (!$result) {
         return false;
     }
     chmod($thumb, 0664);
     return $thumb;
 }
开发者ID:roboshed,项目名称:Zuluru,代码行数:29,代码来源:image_crop.php

示例2: newimg

 function newimg()
 {
     //改变后的图象的比例
     $resize_ratio = $this->resize_width / $this->resize_height;
     //实际图象的比例
     $ratio = $this->width / $this->height;
     if ($this->cut == "1") {
         if ($ratio >= $resize_ratio) {
             $newimg = imagecreatetruecolor($this->resize_width, $this->resize_height);
             imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->height * $resize_ratio, $this->height);
             ImageJpeg($newimg, $this->dstimg);
         }
         if ($ratio < $resize_ratio) {
             $newimg = imagecreatetruecolor($this->resize_width, $this->resize_height);
             imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, $this->width / $resize_ratio);
             ImageJpeg($newimg, $this->dstimg);
         }
     } else {
         if ($ratio >= $resize_ratio) {
             $newimg = imagecreatetruecolor($this->resize_width, $this->resize_width / $ratio);
             imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_width / $ratio, $this->width, $this->height);
             ImageJpeg($newimg, $this->dstimg);
         }
         if ($ratio < $resize_ratio) {
             $newimg = imagecreatetruecolor($this->resize_height * $ratio, $this->resize_height);
             imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_height * $ratio, $this->resize_height, $this->width, $this->height);
             ImageJpeg($newimg, $this->dstimg);
         }
     }
 }
开发者ID:babyhuangshiming,项目名称:webserver,代码行数:30,代码来源:thumb.php

示例3: resize

function resize($photo_src, $width, $name)
{
    $parametr = getimagesize($photo_src);
    list($width_orig, $height_orig) = getimagesize($photo_src);
    $ratio_orig = $width_orig / $height_orig;
    $new_width = $width;
    $new_height = $width / $ratio_orig;
    $newpic = imagecreatetruecolor($new_width, $new_height);
    $col2 = imagecolorallocate($newpic, 255, 255, 255);
    imagefilledrectangle($newpic, 0, 0, $new_width, $new_width, $col2);
    switch ($parametr[2]) {
        case 1:
            $image = imagecreatefromgif($photo_src);
            break;
        case 2:
            $image = imagecreatefromjpeg($photo_src);
            break;
        case 3:
            $image = imagecreatefrompng($photo_src);
            break;
    }
    imagecopyresampled($newpic, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
    imagejpeg($newpic, $name, 100);
    return true;
}
开发者ID:pioytazsko,项目名称:garantmarket,代码行数:25,代码来源:new_item.php

示例4: resize

 /**
  * Automatically resizes an image and returns formatted IMG tag
  *
  * @param string $path Path to the image file, relative to the webroot/img/ directory.
  * @param integer $width Image of returned image
  * @param integer $height Height of returned image
  * @param boolean $aspect Maintain aspect ratio (default: true)
  * @param array	$htmlAttributes Array of HTML attributes.
  * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
  * @return mixed	Either string or echos the value, depends on AUTO_OUTPUT and $return.
  * @access public
  */
 public function resize($path, $width, $height, $aspect = true, $htmlAttributes = array(), $return = false)
 {
     $types = array(1 => "gif", "jpeg", "png", "swf", "psd", "wbmp");
     // used to determine image type
     if (empty($htmlAttributes['alt'])) {
         $htmlAttributes['alt'] = 'thumb';
     }
     // Ponemos alt default
     $uploadsDir = 'uploads';
     $fullpath = ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS . $uploadsDir . DS;
     $url = ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS . $path;
     if (!($size = getimagesize($url))) {
         return;
     }
     // image doesn't exist
     if ($aspect) {
         // adjust to aspect.
         if ($size[1] / $height > $size[0] / $width) {
             // $size[0]:width, [1]:height, [2]:type
             $width = ceil($size[0] / $size[1] * $height);
         } else {
             $height = ceil($width / ($size[0] / $size[1]));
         }
     }
     $relfile = $this->webroot . $uploadsDir . '/' . $this->cacheDir . '/' . $width . 'x' . $height . '_' . basename($path);
     // relative file
     $cachefile = $fullpath . $this->cacheDir . DS . $width . 'x' . $height . '_' . basename($path);
     // location on server
     if (file_exists($cachefile)) {
         $csize = getimagesize($cachefile);
         $cached = $csize[0] == $width && $csize[1] == $height;
         // image is cached
         if (@filemtime($cachefile) < @filemtime($url)) {
             // check if up to date
             $cached = false;
         }
     } else {
         $cached = false;
     }
     if (!$cached) {
         $resize = $size[0] > $width || $size[1] > $height || ($size[0] < $width || $size[1] < $height);
     } else {
         $resize = false;
     }
     if ($resize) {
         $image = call_user_func('imagecreatefrom' . $types[$size[2]], $url);
         if (function_exists("imagecreatetruecolor") && ($temp = imagecreatetruecolor($width, $height))) {
             imagecopyresampled($temp, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
         } else {
             $temp = imagecreate($width, $height);
             imagecopyresized($temp, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
         }
         call_user_func("image" . $types[$size[2]], $temp, $cachefile);
         imagedestroy($image);
         imagedestroy($temp);
     } else {
         //copy($url, $cachefile);
     }
     return $this->output(sprintf($this->Html->tags['image'], $relfile, $this->Html->_parseAttributes($htmlAttributes, null, '', ' ')), $return);
 }
开发者ID:rchavik,项目名称:indent-all-the-things,代码行数:72,代码来源:image.php

示例5: zoom

namespace common;

class upload
{
    //从tmp中移动upload
    public static function zoom(&$file, &$maxWidth = 0, &$maxHeight = 0)
    {
        list($width, $height, $im, $func, $ext) = self::_init($file);
        if (!$im) {
            \yk\log::runlog('file upload error: im not found', 'upload');
            return false;
        }
        if ($maxWidth > 0) {
            $p = max($width / $maxWidth, $height / $maxHeight);
            $dstwidth = intval($width / $p);
            $dstheight = intval($height / $p);
        } else {
            $dstwidth = $width;
            $dstheight = $height;
        }
        $maxWidth = $dstwidth;
        $maxHeight = $dstheight;
        $dstim = imagecreatetruecolor($dstwidth, $dstheight);
        imagealphablending($dstim, false);
        //关闭混杂模式,不可缺少,  PHP文档中说明: (在非混色模式下,画笔颜色连同其 alpha 通道信息一起被拷贝,替换掉目标像素。混色模式在画调色板图像时不可用。)  而且是imagesavealpha方法起作用的前置步骤.
        imagesavealpha($dstim, true);
        //保存 PNG 图像时保存完整的 alpha 通道信息
        $transparent = imagecolorallocatealpha($dstim, 255, 255, 255, 127);
        //取得一个透明的颜色,  透明度在 0-127 间
        imagefill($dstim, 0, 0, $transparent);
        imagecopyresampled($dstim, $im, 0, 0, 0, 0, $dstwidth, $dstheight, $width, $height);
        $file = uniqid() . $ext;
开发者ID:xiaoniainiu,项目名称:php-yaf-yk,代码行数:32,代码来源:upload.php

示例6: hacknrollify

function hacknrollify($picfilename)
{
    $logofilename = "logo.png";
    $logoPicPath = "logopics/" . $logofilename;
    $originalPicPath = "originalpics/" . $picfilename;
    $editedfilename = "hnr_" . $picfilename;
    $editedPicPath = "editedpics/" . $editedfilename;
    // read the original image from file
    $profilepic = imagecreatefromjpeg($originalPicPath);
    $profilepicWidth = imagesx($profilepic);
    $profilepicHeight = imagesy($profilepic);
    // create the black image overlay
    $blackoverlay = imagecreate($profilepicWidth, $profilepicHeight);
    imagecolorallocate($blackoverlay, 0, 0, 0);
    // then merge the black and profilepic
    imagecopymerge($profilepic, $blackoverlay, 0, 0, 0, 0, $profilepicWidth, $profilepicHeight, 50);
    imagedestroy($blackoverlay);
    // merge the resized logo
    $logo = resizeImage($logoPicPath, $profilepicWidth - 80, 999999);
    imageAlphaBlending($logo, false);
    imageSaveAlpha($logo, true);
    $logoWidth = imagesx($logo);
    $logoHeight = imagesy($logo);
    $verticalOffset = $profilepicHeight / 2 - $logoHeight / 2;
    $horizontalOffset = 40;
    imagecopyresampled($profilepic, $logo, $horizontalOffset, $verticalOffset, 0, 0, $logoWidth, $logoHeight, $logoWidth, $logoHeight);
    $mergeSuccess = imagejpeg($profilepic, $editedPicPath);
    if (!$mergeSuccess) {
        echo "Image merge failed!";
    }
    imagedestroy($profilepic);
    imagedestroy($logo);
    return $editedPicPath;
}
开发者ID:nicholaslum444,项目名称:HacknRollify,代码行数:34,代码来源:lib_hacknrollify.php

示例7: thumb

function thumb($filename, $destination = null, $dst_w = null, $dst_h = null, $isReservedSource = false, $scale = 0.5)
{
    list($src_w, $src_h, $imagetype) = getimagesize($filename);
    if (is_null($dst_w) || is_null($dst_h)) {
        $dst_w = ceil($src_w * $scale);
        $dst_h = ceil($src_h * $scale);
    }
    $mime = image_type_to_mime_type($imagetype);
    $createFun = str_replace("/", "createfrom", $mime);
    $outFun = str_replace("/", null, $mime);
    $src_image = $createFun($filename);
    $dst_image = imagecreatetruecolor($dst_w, $dst_h);
    imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
    //image_50/sdfsdkfjkelwkerjle.jpg
    if ($destination && !file_exists(dirname($destination))) {
        mkdir(dirname($destination), 0777, true);
    }
    $dstFilename = $destination == null ? getUniName() . "." . getExt($filename) : $destination;
    $outFun($dst_image, $dstFilename);
    imagedestroy($src_image);
    imagedestroy($dst_image);
    if (!$isReservedSource) {
        unlink($filename);
    }
    return $dstFilename;
}
开发者ID:Wumingla,项目名称:shopImooc,代码行数:26,代码来源:resizeImage2.php

示例8: image

 public static function image($item, $path, $filename)
 {
     $image_tempname1 = $_FILES[$item]['name'];
     $ImageName = $path . $image_tempname1;
     $newfilename = $path . $filename;
     if (move_uploaded_file($_FILES[$item]['tmp_name'], $ImageName)) {
         list($width, $height, $type, $attr) = getimagesize($ImageName);
         if ($type == 2) {
             rename($ImageName, $newfilename);
         } else {
             if ($type == 1) {
                 $image_old = imagecreatefromgif($ImageName);
             } elseif ($type == 3) {
                 $image_old = imagecreatefrompng($ImageName);
             }
             $image_jpg = imagecreatetruecolor($width, $height);
             imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height);
             imagejpeg($image_jpg, $newfilename);
             imagedestroy($image_old);
             imagedestroy($image_jpg);
         }
         return 1;
     } else {
         return 0;
     }
 }
开发者ID:mkrdip,项目名称:Management-Information-System,代码行数:26,代码来源:Input.php

示例9: create_pic

function create_pic($upfile, $new_path, $width)
{
    $quality = 100;
    $image_path = $upfile;
    $image_info = getimagesize($image_path);
    $exname = '';
    //1  =  GIF,  2  =  JPG,  3  =  PNG,  4  =  SWF,  5  =  PSD,  6  =  BMP,  7  =  TIFF(intel  byte  order),  8  =  TIFF(motorola  byte  order),  9  =  JPC,  10  =  JP2,  11  =  JPX,  12  =  JB2,  13  =  SWC,  14  =  IFF
    switch ($image_info[2]) {
        case 1:
            @($image = imagecreatefromgif($image_path));
            $exname = 'gif';
            break;
        case 2:
            @($image = imagecreatefromjpeg($image_path));
            $exname = 'jpg';
            break;
        case 3:
            @($image = imagecreatefrompng($image_path));
            $exname = 'png';
            break;
        case 6:
            @($image = imagecreatefromwbmp($image_path));
            $exname = 'wbmp';
            break;
    }
    $T_width = $image_info[0];
    $T_height = $image_info[1];
    if (!empty($image)) {
        $image_x = imagesx($image);
        $image_y = imagesy($image);
    } else {
        return FALSE;
    }
    @chmod($new_path, 0777);
    if ($image_x > $width) {
        $x = $width;
        $y = intval($x * $image_y / $image_x);
    } else {
        @copy($image_path, $new_path . '.' . $exname);
        return $exname;
    }
    $newimage = imagecreatetruecolor($x, $y);
    imagecopyresampled($newimage, $image, 0, 0, 0, 0, $x, $y, $image_x, $image_y);
    switch ($image_info[2]) {
        case 1:
            imagegif($newimage, $new_path . '.gif', $quality);
            break;
        case 2:
            imagejpeg($newimage, $new_path . '.jpg', $quality);
            break;
        case 3:
            imagepng($newimage, $new_path . '.png', $quality);
            break;
        case 6:
            imagewbmp($newimage, $new_path . '.wbmp', $quality);
            break;
    }
    imagedestroy($newimage);
    return $exname;
}
开发者ID:yunsite,项目名称:cyaskuc,代码行数:60,代码来源:global.func.php

示例10: apply

 /**
  * {@inheritdoc}
  */
 public function apply(&$image)
 {
     $inputWidth = imagesx($image);
     $inputHeight = imagesy($image);
     $width = $inputWidth;
     $height = $inputHeight;
     // bigger
     if ($height < $this->outputHeight) {
         $width = $this->outputHeight / $height * $width;
         $height = $this->outputHeight;
     }
     if ($width < $this->outputWidth) {
         $height = $this->outputWidth / $width * $height;
         $width = $this->outputWidth;
     }
     // taller
     if ($height > $this->outputHeight) {
         $width = $this->outputHeight / $height * $width;
         $height = $this->outputHeight;
     }
     // wider
     if ($width > $this->outputWidth) {
         $height = $this->outputWidth / $width * $height;
         $width = $this->outputWidth;
     }
     $output = imagecreatetruecolor($width, $height);
     imagecopyresampled($output, $image, 0, 0, 0, 0, $width, $height, $inputWidth, $inputHeight);
     $image = $output;
 }
开发者ID:moust,项目名称:paint,代码行数:32,代码来源:Resize.php

示例11: resize_image

function resize_image($file, $w, $h, $crop = FALSE)
{
    list($width, $height) = getimagesize($file);
    $r = $width / $height;
    if ($crop) {
        if ($width > $height) {
            $width = ceil($width - $width * abs($r - $w / $h));
        } else {
            $height = ceil($height - $height * abs($r - $w / $h));
        }
        $newwidth = $w;
        $newheight = $h;
    } else {
        if ($w / $h > $r) {
            $newwidth = $h * $r;
            $newheight = $h;
        } else {
            $newheight = $w / $r;
            $newwidth = $w;
        }
    }
    $src = imagecreatefromjpeg($file);
    $dst = imagecreatetruecolor($newwidth, $newheight);
    imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    return $dst;
}
开发者ID:weihetian,项目名称:gallery,代码行数:26,代码来源:upload.php

示例12: resizer

function resizer($filename, $copypath, $MaxWidth, $MaxHeight)
{
    //cesta k souboru, ktery chcete zmensit cesta, kam zmenseny soubor ulozit maximalni sirka zmenseneho obrazku   //maximalni vyska zmenseneho obrazku
    //zjistime puvodni velikost obrazku
    list($OrigWidth, $OrigHeight) = getimagesize($filename);
    //hodnota 0 v parametrech MaxWidth resp. MaxHeight znamena, ze sirka resp. vyska vysledku muze byt libovolna
    if ($MaxWidth == 0) {
        $MaxWidth = $OrigWidth;
    }
    if ($MaxHeight == 0) {
        $MaxHeight = $OrigHeight;
    }
    //nyni vypocitam pomer zmenseni
    $pw = $OrigWidth / $MaxWidth;
    $ph = $OrigHeight / $MaxHeight;
    if ($pw > $ph) {
        $p = $pw;
    } else {
        $p = $ph;
    }
    if ($p < 1) {
        $p = 1;
    }
    //v p ted mame pomer pro zmenseni vypocitame vysku a sirku zmenseneho obrazku
    $NewWidth = (int) $OrigWidth / $p;
    $NewHeight = (int) $OrigHeight / $p;
    //vytvorime novy obrazek pozadovane vysky a sirky
    $image_p = imagecreatetruecolor($NewWidth, $NewHeight);
    //otevreme puvodni obrazek se souboru
    $image = imagecreatefromjpeg($filename);
    //a okopirujeme zmenseny puvodni obrazek do noveho
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $NewWidth, $NewHeight, $OrigWidth, $OrigHeight);
    //a ulozime
    imagejpeg($image_p, $copypath, 100);
}
开发者ID:GE3,项目名称:GE3,代码行数:35,代码来源:galerie.php

示例13: scale

 function scale($maxW, $maxH, $fitType = FALSE)
 {
     if (!is_resource($this->prcImg['resoc'])) {
         $this->prcImg = $this->srcImg;
     }
     $w = $this->prcImg['w'];
     $h = $this->prcImg['h'];
     $xRatio = $maxW / $w;
     $yRatio = $maxH / $h;
     if ($w <= $maxW && $h <= $maxH) {
         $newW = $maxW;
         $newH = $maxH;
     } else {
         if ($xRatio * $h < $maxH) {
             $newH = ceil($xRatio * $h);
             $newW = $maxW;
         } else {
             $newW = ceil($yRatio * $w);
             $newH = $maxH;
         }
     }
     if ($fitType == 'BOTH') {
         $newW = $maxW;
         $newH = $maxH;
     }
     $imageHandle = imagecreatetruecolor($newW, $newH);
     imagecopyresampled($imageHandle, $this->prcImg['resoc'], 0, 0, 0, 0, $newW, $newH, $this->prcImg['w'], $this->prcImg['h']);
     $this->prcImg['resoc'] = $imageHandle;
 }
开发者ID:badtux,项目名称:pmg,代码行数:29,代码来源:image2.class.php

示例14: modify

 /**
  * Wrapper function for 'imagecopyresampled'
  *
  * @param  Image   $image
  * @param  integer $dst_x
  * @param  integer $dst_y
  * @param  integer $src_x
  * @param  integer $src_y
  * @param  integer $dst_w
  * @param  integer $dst_h
  * @param  integer $src_w
  * @param  integer $src_h
  * @return boolean
  */
 protected function modify($image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
 {
     foreach ($image as $frame) {
         // create new image
         $modified = imagecreatetruecolor($dst_w, $dst_h);
         // get current image
         $resource = $frame->getCore();
         // preserve transparency
         $transIndex = imagecolortransparent($resource);
         if ($transIndex != -1) {
             $rgba = imagecolorsforindex($modified, $transIndex);
             $transColor = imagecolorallocatealpha($modified, $rgba['red'], $rgba['green'], $rgba['blue'], 127);
             imagefill($modified, 0, 0, $transColor);
             imagecolortransparent($modified, $transColor);
         } else {
             imagealphablending($modified, false);
             imagesavealpha($modified, true);
         }
         // copy content from resource
         imagecopyresampled($modified, $resource, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
         // free memory of old core
         imagedestroy($resource);
         // set new content as recource
         $frame->setCore($modified);
     }
     return true;
 }
开发者ID:EdgarPost,项目名称:image,代码行数:41,代码来源:ResizeCommand.php

示例15: upload

function upload($tmp, $name, $nome, $larguraP, $pasta)
{
    $ext = strtolower(end(explode('.', $name)));
    if ($ext == 'jpg') {
        $img = imagecreatefromjpeg($tmp);
    } elseif ($ext == 'gif') {
        $img = imagecreatefromgif($tmp);
    } else {
        $img = imagecreatefrompng($tmp);
    }
    $x = imagesx($img);
    $y = imagesy($img);
    $largura = $x > $larguraP ? $larguraP : $x;
    $altura = $largura * $y / $x;
    if ($altura > $larguraP) {
        $altura = $larguraP;
        $largura = $altura * $x / $y;
    }
    $nova = imagecreatetruecolor($largura, $altura);
    imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura, $altura, $x, $y);
    imagejpeg($nova, "{$pasta}/{$nome}");
    imagedestroy($img);
    imagedestroy($nova);
    return $nome;
}
开发者ID:mauriliovilela,项目名称:ser-social,代码行数:25,代码来源:funcoes.php


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