• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP imagecopyresampled函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: cropnsave

 public function cropnsave($id)
 {
     $basepath = app_path() . '/storage/uploads/';
     $jpeg_quality = 90;
     $src = $basepath . 'resize_' . $id;
     if (ImageModel::getImgTypeByExtension($id) == ImageModel::IMGTYPE_PNG) {
         $img_r = imagecreatefrompng($src);
     } else {
         $img_r = imagecreatefromjpeg($src);
     }
     $dst_r = ImageCreateTrueColor(Input::get('w'), Input::get('h'));
     imagecopyresampled($dst_r, $img_r, 0, 0, Input::get('x'), Input::get('y'), Input::get('w'), Input::get('h'), Input::get('w'), Input::get('h'));
     $filename = $basepath . 'crop_' . $id;
     imagejpeg($dst_r, $filename, $jpeg_quality);
     $image = ImageModel::createImageModel('crop_' . $id);
     try {
         $session = Session::get('user');
         $userService = new SoapClient(Config::get('wsdl.user'));
         $currentUser = $userService->getUserById(array("userId" => $session['data']->id));
         $currentUser = $currentUser->user;
         $currentUser->avatar = $image;
         $result = $userService->updateUser(array("user" => $currentUser));
         // Cleanup
         File::delete($src);
         File::delete($filename);
         File::delete($basepath . $id);
         return Response::json($result->complete);
     } catch (Exception $ex) {
         error_log($ex);
     }
 }
开发者ID:Yatko,项目名称:Gifteng,代码行数:31,代码来源:ImageController.php


示例17: createthumb

function createthumb($originalImage, $new_w, $new_h)
{
    $src_img = imagecreatefromjpeg("uploads/" . $originalImage);
    # Add the _t to our image name
    list($imageName, $extension) = explode(".", $originalImage);
    $newName = $imageName . "_t." . $extension;
    # Maintain proportions
    $old_x = imageSX($src_img);
    $old_y = imageSY($src_img);
    if ($old_x > $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $old_y * ($new_h / $old_x);
    }
    if ($old_x < $old_y) {
        $thumb_w = $old_x * ($new_w / $old_y);
        $thumb_h = $new_h;
    }
    if ($old_x == $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    # Create destination-image-resource
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    # Copy source-image-resource to destination-image-resource
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    # Create the final image from the destination-image-resource
    imagejpeg($dst_img, "uploads/" . $newName);
    # Delete our image-resources
    imagedestroy($dst_img);
    imagedestroy($src_img);
    # Show results
    return $newName;
}
开发者ID:ritarafaeli,项目名称:notes,代码行数:33,代码来源:uploaderExample_functions.php


示例18: filter

 public function filter($value)
 {
     if (!file_exists($value)) {
         throw new Zend_Filter_Exception('Image does not exist: ' . $value);
     }
     $image = imagecreatefromstring(file_get_contents($value));
     if (false === $image) {
         throw new Zend_Filter_Exception('Can\'t load image: ' . $value);
     }
     // find ratio to scale down to
     // TODO: pass 600 as parameter in the future
     $origWidth = imagesx($image);
     $origHeight = imagesy($image);
     $ratio = max($origWidth, $origHeight) / 600;
     if ($ratio > 1) {
         // img too big! create a scaled down image
         $newWidth = round($origWidth / $ratio);
         $newHeight = round($origHeight / $ratio);
         $resized = imagecreatetruecolor($newWidth, $newHeight);
         imagecopyresampled($resized, $image, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight);
         // determine type and store to disk
         $explodeResult = explode(".", $value);
         $type = strtolower($explodeResult[count($explodeResult) - 1]);
         $writeFunc = 'image' . $type;
         if ($type == 'jpeg' || $type == 'jpg') {
             imagejpeg($resized, $value, 100);
         } else {
             $writeFunc($resized, $value);
         }
     }
     return $value;
 }
开发者ID:RadioCampusFrance,项目名称:airtime,代码行数:32,代码来源:ImageSize.php


示例19: fastimagecopyresampled

function fastimagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3)
{
    // Plug-and-Play fastimagecopyresampled function replaces much slower imagecopyresampled.
    // Just include this function and change all "imagecopyresampled" references to "fastimagecopyresampled".
    // Typically from 30 to 60 times faster when reducing high resolution images down to thumbnail size using the default quality setting.
    // Author: Tim Eckel - Date: 09/07/07 - Version: 1.1 - Project: FreeRingers.net - Freely distributable - These comments must remain.
    //
    // Optional "quality" parameter (defaults is 3). Fractional values are allowed, for example
    // 1.5. Must be greater than zero.
    // Between 0 and 1 = Fast, but mosaic results, closer to 0 increases the mosaic effect.
    // 1 = Up to 350 times faster. Poor results, looks very similar to imagecopyresized.
    // 2 = Up to 95 times faster.  Images appear a little sharp, some prefer this over a quality of 3.
    // 3 = Up to 60 times faster.  Will give high quality smooth results very close to imagecopyresampled, just faster.
    // 4 = Up to 25 times faster.  Almost identical to imagecopyresampled for most images.
    // 5 = No speedup. Just uses imagecopyresampled, no advantage over imagecopyresampled.
    if (empty($src_image) || empty($dst_image) || $quality <= 0) {
        return false;
    }
    if ($quality < 5 && ($dst_w * $quality < $src_w || $dst_h * $quality < $src_h)) {
        $temp = imagecreatetruecolor($dst_w * $quality + 1, $dst_h * $quality + 1);
        imagecopyresized($temp, $src_image, 0, 0, $src_x, $src_y, $dst_w * $quality + 1, $dst_h * $quality + 1, $src_w, $src_h);
        imagecopyresampled($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $dst_w * $quality, $dst_h * $quality);
        imagedestroy($temp);
    } else {
        imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    }
    return true;
}
开发者ID:njanani,项目名称:olio-cassandra,代码行数:28,代码来源:ImageUtil.php


示例20: foundation_process_image_file

function foundation_process_image_file($file_name, $setting_name)
{
    if ($setting_name->domain == FOUNDATION_SETTING_DOMAIN && $setting_name->name == 'logo_image') {
        // Need to make sure this isn't too big
        if (function_exists('getimagesize') && function_exists('imagecreatefrompng') && function_exists('imagecopyresampled') && function_exists('imagepng')) {
            $size = getimagesize($file_name);
            if ($size) {
                $width = $size[0];
                $height = $size[1];
                if ($size['mime'] == 'image/png') {
                    if ($width > FOUNDATION_MAX_LOGO_SIZE) {
                        $new_width = FOUNDATION_MAX_LOGO_SIZE;
                        $new_height = $height * $new_width / $width;
                        $src_image = imagecreatefrompng($file_name);
                        $saved_image = imagecreatetruecolor($new_width, $new_height);
                        // Preserve Transparency
                        imagecolortransparent($saved_image, imagecolorallocate($saved_image, 0, 0, 0));
                        imagecopyresampled($saved_image, $src_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                        // Get rid of the old file
                        unlink($file_name);
                        // New image, compression level 5 (make it a bit smaller)
                        imagepng($saved_image, $file_name, 5);
                    }
                }
            }
        }
    }
}
开发者ID:sb-xs,项目名称:que-pour-elle,代码行数:28,代码来源:root-functions.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP imagecopyresized函数代码示例发布时间:2022-05-24
下一篇:
PHP image_constrain_size_for_editor函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap