php 缩略图生成类,支持imagemagick及gd库两种处理

php图片处理扩展GD vs ImageMagick(Imagick) 两者都是php常用的扩展,GD是自带的,ImageMagick是需要安装扩展的.还有个GMagick(这货是ImageMagick的衍生分支,并没有鼓吹的多么完美.) 那么两者性能如何呢? 1.资源调用方面,ImageMagick胜 由于ImageMagick源自扩展,调用系统os资源,所以不受限于php设置,比如内存.但GD则受限于php了. 2.图片大小方面,GD胜 通常在处理小文件例如720... 阅读详情
功能:
1.按比例缩小/放大
2.填充背景色
3.按区域裁剪
4.添加水印,包括水印的位置,透明度等

使用imagemagick/GD库实现,imagemagick地址:www.imagemagick.org
需要安装imagemagick,安装方法如下:点击查看

PicThumb.class.php

<?php
/** 缩略图生成类,支持imagemagick及gd库两种处理
*   Date:   2013-07-15
*   Author: fdipzone
*   Ver:    1.2
*
*   Func:
*   public  set_config: 设置参数
*   public  create_thumb: 生成缩略图
*   private fit: 缩略图片
*   private crop: 裁剪图片
*   private gd_fit: GD库缩略图片
*   private gd_crop: GD库裁剪图片
*   private get_size: 获取要转换的size
*   private get_crop_offset: 获取裁图的偏移量
*   private add_watermark: 添加水印
*   private check_handler: 判断处理程序是否已安装
*   private create_dirs: 创建目录
*   private exists: 判断参数是否存在
*   private to_log: 记录log
*   private hex2rgb: hex颜色转rgb颜色
*   private get_file_ext: 获取图片类型
*
*   ver:    1.1 增加GD库处理
*   ver:    1.2 增加width,height错误参数处理
*               增加当图片colorspace不为RGB时作转RGB处理
*               修正使用crop保存为gif时出现透明无效区域问题,使用+repage参数,删除透明无效区域即可
*
*   tips:建议使用imagemagick
*        GD库不支持透明度水印,如果必须使用透明水印,请将水印图片做成有透明度。
*        GD库输出gif如加透明水印,会有问题。
*/

class PicThumb{ // class start

    private $_log = null;            // log file
    private $_handler = null;        // 进行图片处理的程序,imagemagick/gd库
    private $_type = 'fit';          // fit or crop
    private $_source = null;         // 原图路径
    private $_dest = null;           // 缩略图路径
    private $_watermark = null;      // 水印图片
    private $_opacity = 75;          // 水印圖片透明度,gd库不支持
    private $_gravity = 'SouthEast'; // 水印摆放位置 NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast
    private $_geometry = '+10+10';   // 水印定位,gd库不支持
    private $_croppos = 'TL';        // 截图的位置 TL TM TR ML MM MR BL BM BR
    private $_bgcolor = null;        // 填充的背景色
    private $_quality = 90;          // 生成的图片质量
    private $_width = null;          // 指定区域宽度
    private $_height = null;         // 指定区域高度


    // 初始化
    public function __construct($logfile=''){
        if($logfile!=''){
            $this->_log = $logfile;
        }
    }


    // 设置参数
    public function set_config($param=array()){
        $this->_handler = $this->exists($param, 'handler')? strtolower($param['handler']) : null;
        $this->_type = $this->exists($param, 'type')? strtolower($param['type']) : 'fit';
        $this->_watermark = $this->exists($param, 'watermark')? $param['watermark'] : null;
        $this->_opacity = $this->exists($param, 'opacity')? $param['opacity'] : 75;
        $this->_gravity = $this->exists($param, 'gravity')? $param['gravity'] : 'SouthEast';
        $this->_geometry = $this->exists($param, 'geometry')? $param['geometry'] : '+10+10';
        $this->_croppos = $this->exists($param, 'croppos')? $param['croppos'] : 'TL';
        $this->_bgcolor = $this->exists($param, 'bgcolor')? $param['bgcolor'] : null;
        $this->_quality = $this->exists($param, 'quality')? $param['quality'] : 90;
        $this->_width = $this->exists($param, 'width')? $param['width'] : null;
        $this->_height = $this->exists($param, 'height')? $param['height'] : null;
    }


    /** 创建缩略图
    * @param String $source 原图
    * @param String $dest   目标图
    * @return boolean
    */
    public function create_thumb($source, $dest){

        // 检查使用的handler是否已安装
        if(!$this->check_handler()){
            $this->to_log('handler not installed');
            return false;
        }

        // 判断区域宽高是否正确
        if(!is_numeric($this->_width) || !is_numeric($this->_height) || $this->_width<=0 || $this->_height<=0){
            $this->to_log('width or height invalid');
            return false;
        }

        // 判断源文件是否存在
        if(!file_exists($source)){
            $this->to_log($source.' not exists');
            return false;
        }

        // 创建目标文件路径
        if(!$this->create_dirs($dest)){
            $this->to_log(dirname($dest).' create fail');
            return false;
        }

        $this->_source = $source;   // 源文件
        $this->_dest = $dest;       // 目标文件

        // 处理图片
        switch($this->_type){
            case 'fit':
                if($this->_handler=='imagemagick'){
                    return $this->fit();
                }else{
                    return $this->gd_fit();
                }
                break;

            case 'crop':
                if($this->_handler=='imagemagick'){
                    return $this->crop();
                }else{
                    return $this->gd_crop();
                }
                break;

            default:
                $this->to_log($this->_type.' not fit and crop');
                return false;
        }

    }


    /** 按比例压缩或拉伸图片
    * @return boolean
    */
    private function fit(){

        // 判断是否填充背景
        $bgcolor = ($this->_bgcolor!=null)? 
        sprintf(" -background '%s' -gravity center -extent '%sx%s' ", $this->_bgcolor, $this->_width, $this->_height) : "";

        // 判断是否要转为RGB
        $source_info = getimagesize($this->_source);
        $colorspace = (!isset($source_info['channels']) || $source_info['channels']!=3)? ' -colorspace RGB ' : '';

        // 命令行
        $cmd = sprintf("convert -resize '%sx%s' '%s' %s -quality %s %s '%s'", $this->_width, $this->_height, $this->_source, $bgcolor, $this->_quality, $colorspace, $this->_dest);

        // 记录执行的命令
        $this->to_log($cmd);

        // 执行命令
        exec($cmd);

        // 添加水印
        $this->add_watermark($this->_dest);

        return is_file($this->_dest)? true : false;

    }


    /** 裁剪图片
    * @return boolean
    */
    private function crop(){

        // 获取生成的图片尺寸
        list($pic_w, $pic_h) = $this->get_size();

        // 获取截图的偏移量
        list($offset_w, $offset_h) = $this->get_crop_offset($pic_w, $pic_h);

        // 判断是否要转为RGB
        $source_info = getimagesize($this->_source);
        $colorspace = (!isset($source_info['channels']) || $source_info['channels']!=3)? ' -colorspace RGB ' : '';

        // 命令行
        $cmd = sprintf("convert -resize '%sx%s' '%s' -quality %s %s -crop %sx%s+%s+%s +repage '%s'", $pic_w, $pic_h, $this->_source, $this->_quality, $colorspace, $this->_width, $this->_height, $offset_w, $offset_h, $this->_dest);

        // 记录执行的命令
        $this->to_log($cmd);

        // 执行命令
        exec($cmd);

        // 添加水印
        $this->add_watermark($this->_dest);

        return is_file($this->_dest)? true : false;

    }


    /** GD库按比例压缩或拉伸图片
    * @return boolean
    */
    private function gd_fit(){

        // 获取生成的图片尺寸
        list($pic_w, $pic_h) = $this->get_size();

        list($owidth, $oheight, $otype) = getimagesize($this->_source);

        switch($otype){
            case 1: $source_img = imagecreatefromgif($this->_source); break;
            case 2: $source_img = imagecreatefromjpeg($this->_source); break;
            case 3: $source_img = imagecreatefrompng($this->_source); break;
            default: return false;
        }

        // 按比例缩略/拉伸图片
        $new_img = imagecreatetruecolor($pic_w, $pic_h);
        imagecopyresampled($new_img, $source_img, 0, 0, 0, 0, $pic_w, $pic_h, $owidth, $oheight);

        // 判断是否填充背景
        if($this->_bgcolor!=null){
            $bg_img = imagecreatetruecolor($this->_width, $this->_height);
            $rgb = $this->hex2rgb($this->_bgcolor);
            $bgcolor =imagecolorallocate($bg_img, $rgb['r'], $rgb['g'], $rgb['b']);
            imagefill($bg_img, 0, 0, $bgcolor);
            imagecopy($bg_img, $new_img, (int)(($this->_width-$pic_w)/2), (int)(($this->_height-$pic_h)/2), 0, 0, $pic_w, $pic_h);
            $new_img = $bg_img;
        }

        // 获取目标图片的类型
        $dest_ext = $this->get_file_ext($this->_dest);

        // 生成图片
        switch($dest_ext){
            case 1: imagegif($new_img, $this->_dest, $this->_quality); break;
            case 2: imagejpeg($new_img, $this->_dest, $this->_quality); break;
            case 3: imagepng($new_img, $this->_dest, (int)(($this->_quality-1)/10)); break;
        }

        if(isset($source_img)){
            imagedestroy($source_img);
        }

        if(isset($new_img)){
            imagedestroy($new_img);
        }

        // 添加水印
        $this->add_watermark($this->_dest);

        return is_file($this->_dest)? true : false;

    }


    /** GD库裁剪图片
    * @return boolean
    */
    private function gd_crop(){

        // 获取生成的图片尺寸
        list($pic_w, $pic_h) = $this->get_size();

        // 获取截图的偏移量
        list($offset_w, $offset_h) = $this->get_crop_offset($pic_w, $pic_h);

        list($owidth, $oheight, $otype) = getimagesize($this->_source);

        switch($otype){
            case 1: $source_img = imagecreatefromgif($this->_source); break;
            case 2: $source_img = imagecreatefromjpeg($this->_source); break;
            case 3: $source_img = imagecreatefrompng($this->_source); break;
            default: return false;
        }

        // 按比例缩略/拉伸图片
        $tmp_img = imagecreatetruecolor($pic_w, $pic_h);
        imagecopyresampled($tmp_img, $source_img, 0, 0, 0, 0, $pic_w, $pic_h, $owidth, $oheight);

        // 裁剪图片
        $new_img = imagecreatetruecolor($this->_width, $this->_height);
        imagecopyresampled($new_img, $tmp_img, 0, 0, $offset_w, $offset_h, $this->_width, $this->_height, $this->_width, $this->_height);

        // 获取目标图片的类型
        $dest_ext = $this->get_file_ext($this->_dest);

        // 生成图片
        switch($dest_ext){
            case 1: imagegif($new_img, $this->_dest, $this->_quality); break;
            case 2: imagejpeg($new_img, $this->_dest, $this->_quality); break;
            case 3: imagepng($new_img, $this->_dest, (int)(($this->_quality-1)/10)); break;
        }

        if(isset($source_img)){
            imagedestroy($source_img);
        }

        if(isset($tmp_img)){
            imagedestroy($tmp_img);
        }

        if(isset($new_img)){
            imagedestroy($new_img);
        }

        // 添加水印
        $this->add_watermark($this->_dest);

        return is_file($this->_dest)? true : false;

    }


    /** 获取目标图生成的size
    * @return Array $width, $height
    */
    private function get_size(){
        list($owidth, $oheight) = getimagesize($this->_source);
        $width = (int)($this->_width);
        $height = (int)($this->_height);
        
        switch($this->_type){
            case 'fit':
                $pic_w = $width;
                $pic_h = (int)($pic_w*$oheight/$owidth);
                if($pic_h>$height){
                    $pic_h = $height;
                    $pic_w = (int)($pic_h*$owidth/$oheight);
                }
                break;
            case 'crop':
                $pic_w = $width;
                $pic_h = (int)($pic_w*$oheight/$owidth);
                if($pic_h<$height){
                    $pic_h = $height;
                    $pic_w = (int)($pic_h*$owidth/$oheight);
                }
                break;
        }

        return array($pic_w, $pic_h);
    }


    /** 获取截图的偏移量
    * @param int $pic_w 图宽度
    * @param int $pic_h 图高度
    * @return Array $offset_w, $offset_h
    */
    private function get_crop_offset($pic_w, $pic_h){
        $offset_w = 0;
        $offset_h = 0;
        
        switch(strtoupper($this->_croppos)){
            case 'TL':
                $offset_w = 0;
                $offset_h = 0;
                break;

            case 'TM':
                $offset_w = (int)(($pic_w-$this->_width)/2);
                $offset_h = 0;
                break;

            case 'TR':
                $offset_w = (int)($pic_w-$this->_width);
                $offset_h = 0;
                break;

            case 'ML':
                $offset_w = 0;
                $offset_h = (int)(($pic_h-$this->_height)/2);
                break;

            case 'MM':
                $offset_w = (int)(($pic_w-$this->_width)/2);
                $offset_h = (int)(($pic_h-$this->_height)/2);
                break;

            case 'MR':
                $offset_w = (int)($pic_w-$this->_width);
                $offset_h = (int)(($pic_h-$this->_height)/2);
                break;

            case 'BL':
                $offset_w = 0;
                $offset_h = (int)($pic_h-$this->_height);
                break;

            case 'BM':
                $offset_w = (int)(($pic_w-$this->_width)/2);
                $offset_h = (int)($pic_h-$this->_height);
                break;

            case 'BR':
                $offset_w = (int)($pic_w-$this->_width);
                $offset_h = (int)($pic_h-$this->_height);
                break;
        }

        return array($offset_w, $offset_h);
    }


    /** 添加水印
    * @param String $dest 图片路径
    */
    private function add_watermark($dest){
        if($this->_watermark!=null && file_exists($this->_watermark) && file_exists($dest)){
            list($owidth, $oheight, $otype) = getimagesize($dest);
            list($w, $h, $wtype) = getimagesize($this->_watermark);

            // 水印图比原图要小才加水印
            if($w<=$owidth && $h<=$oheight){

                if($this->_handler=='imagemagick'){ // imagemagick 添加水印

                    $cmd = sprintf("composite -gravity %s -geometry %s -dissolve %s '%s' %s %s", $this->_gravity, $this->_geometry, $this->_opacity, $this->_watermark, $dest, $dest);

                    $this->to_log($cmd);

                    exec($cmd);

                }else{ // gd 添加水印

                    switch($wtype){
                        case 1: $water_img = imagecreatefromgif($this->_watermark); break;
                        case 2: $water_img = imagecreatefromjpeg($this->_watermark); break;
                        case 3: $water_img = imagecreatefrompng($this->_watermark); break;
                        default: return false;
                    }

                    switch($otype){
                        case 1: $dest_img = imagecreatefromgif($dest); break;
                        case 2: $dest_img = imagecreatefromjpeg($dest); break;
                        case 3: $dest_img = imagecreatefrompng($dest); break;
                        default: return false;
                    }

                    // 水印位置
                    switch(strtolower($this->_gravity)){
                        case 'northwest':
                            $posX = 0;
                            $posY = 0;
                            break;
                        case 'north':
                            $posX = ($owidth - $w) / 2;
                            $posY = 0;
                            break;
                        case 'northeast':
                            $posX = $owidth - $w;
                            $posY = 0;
                            break;
                        case 'west':
                            $posX = 0;
                            $posY = ($oheight - $h) / 2;
                            break;
                        case 'center':
                            $posX = ($owidth - $w) / 2;
                            $posY = ($oheight - $h) / 2;
                            break;
                        case 'east':
                            $posX = $owidth - $w;
                            $posY = ($oheight - $h) / 2;
                            break;
                        case 'southwest':
                            $posX = 0;
                            $posY = $oheight - $h;
                            break;
                        case 'south':
                            $posX = ($owidth - $w) / 2;
                            $posY = $oheight - $h;
                            break;
                        case 'southeast':
                            $posX = $owidth - $w;
                            $posY = $oheight - $h;
                            break;
                    }

                    imagealphablending($dest_img, true);
                    imagecopy($dest_img, $water_img, $posX, $posY, 0, 0, $w, $h);

                    switch($otype){
                        case 1:imagegif($dest_img, $dest, $this->_quality); break;
                        case 2:imagejpeg($dest_img, $dest, $this->_quality); break;
                        case 3:imagepng($dest_img, $dest, (int)(($this->_quality-1)/10)); break;
                    }

                    if(isset($water_img)){
                        imagedestroy($water_img);
                    }

                    if(isset($dest_img)){
                        imagedestroy($dest_img);
                    }

                }
            }
        }
    }


    /** 判断处理程序是否已安装
    * @return boolean
    */
    private function check_handler(){

        $handler = $this->_handler;

        if(!in_array($handler, array('imagemagick', 'gd', null))){
            return false;
        }

        // 检查是否有安装imagemagick
        $imagemagick_installed = strstr(shell_exec('convert -version'),'Version: ImageMagick')!=''? true : false;

        // 检查是否有安装gd库
        $gd_installed = function_exists('gd_info')? true : false;

        switch($handler){
            case 'imagemagick':
                return $imagemagick_installed;
                break;

            case 'gd':
                return $gd_installed;
                break;

            case null:
                if($imagemagick_installed){
                    $this->_handler = 'imagemagick';
                    return true;
                }

                if($gd_installed){
                    $this->_handler = 'gd';
                    return true;
                }
                break;
        }

        return false;
    }


    /** 创建图片目录
    * @param String $path
    * @return boolean
    */
    private function create_dirs($dest){
        if(!is_dir(dirname($dest))){
            return mkdir(dirname($dest), 0777, true);
        }
        return true;
    }


    /** 判断参数是否存在
    * @param  Array   $obj  数组对象
    * @param  String  $key  要查找的key
    * @return boolean
    */
    private function exists($obj,$key=''){
        if($key==''){
            return isset($obj) && !empty($obj);
        }else{
            $keys = explode('.',$key);
            for($i=0,$max=count($keys); $i<$max; $i++){
                if(isset($obj[$keys[$i]])){
                    $obj = $obj[$keys[$i]];
                }else{
                    return false;
                }
            }
            return isset($obj) && !empty($obj);
        }
    }


    /** 记录log
    * @param String $msg 要记录的log讯息
    */
    private function to_log($msg){
        if($this->_log){
            $msg = '['.date('Y-m-d H:i:s').']'.$msg."\r\n";
            file_put_contents($this->_log, $msg, FILE_APPEND);
        }
    }


    /** hex颜色转rgb颜色
    * @param  String $color hex颜色
    * @return Array
    */
    private function hex2rgb($hexcolor){
        $color = str_replace('#', '', $hexcolor);
        if (strlen($color) > 3) {
            $rgb = array(
                'r' => hexdec(substr($color, 0, 2)),
                'g' => hexdec(substr($color, 2, 2)),
                'b' => hexdec(substr($color, 4, 2))
            );
        } else {
            $r = substr($color, 0, 1) . substr($color, 0, 1);
            $g = substr($color, 1, 1) . substr($color, 1, 1);
            $b = substr($color, 2, 1) . substr($color, 2, 1);
            $rgb = array(
                'r' => hexdec($r),
                'g' => hexdec($g),
                'b' => hexdec($b)
            );
        }
        return $rgb;
    }


    /** 获取图片类型
    * @param  String $file 图片路径
    * @return int
    */
    private function get_file_ext($file){
        $filename = basename($file);
        list($name, $ext)= explode('.', $filename);

        $ext_type = 0;

        switch(strtolower($ext)){
            case 'jpg':
            case 'jpeg':
                $ext_type = 2;
                break;
            case 'gif':
                $ext_type = 1;
                break;
            case 'png':
                $ext_type = 3;
                break;
        }

        return $ext_type;
    }

} // class end

?>
demo:
<?php
define('ROOT', dirname(__FILE__));

require(ROOT."/PicThumb.class.php");

$logfile = ROOT.'/PicThumb.log';
$source1 = ROOT.'/pic/source.jpg';
$dest1 = ROOT.'/pic/1.jpg';
$dest2 = ROOT.'/pic/2.gif';
$dest3 = ROOT.'/pic/3.png';

$source2 = ROOT.'/pic/source_cmyk.jpg';
$dest4 = ROOT.'/pic/4.jpg';
$dest5 = ROOT.'/pic/5.gif';
$dest6 = ROOT.'/pic/6.png';

$watermark = ROOT.'/pic/watermark.png';

// 按比例生成缩略图
$param = array(
    'type' => 'fit',
    'width' => 100,
    'height' => 100,
);

$obj = new PicThumb($logfile);
$obj->set_config($param);
$flag = $obj->create_thumb($source1, $dest1);

if($flag){
    echo '<img src="pic/'.basename($dest1).'">';
}else{
    echo 'create thumb fail';
}


// 按比例生成缩略图,不足部分用#FF0000填充
$param = array(
    'type' => 'fit',
    'width' => 100,
    'height' => 100,
    'bgcolor' => '#FFFF00'
);

$obj = new PicThumb($logfile);
$obj->set_config($param);
$flag = $obj->create_thumb($source1, $dest2);

if($flag){
    echo '<img src="pic/'.basename($dest2).'">';
}else{
    echo 'create thumb fail';
}


// 裁剪250x250的缩略图,裁剪位置是底部中间,水印位置西南,透明度50
$param = array(
    'type' => 'crop',
    'croppos' => 'BM',
    'width' => 250,
    'height' => 250,
    'watermark' => $watermark,
    'opacity' => 50,
    'gravity' => 'SouthWest'
);

$obj = new PicThumb($logfile);
$obj->set_config($param);
$flag = $obj->create_thumb($source1, $dest3);

if($flag){
    echo '<img src="pic/'.basename($dest3).'">';
}else{
    echo 'create thumb fail';
}


// 按比例生成缩略图 CMYK格式
$param = array(
    'type' => 'fit',
    'width' => 100,
    'height' => 100,
);

$obj = new PicThumb($logfile);
$obj->set_config($param);
$flag = $obj->create_thumb($source2, $dest4);

if($flag){
    echo '<img src="pic/'.basename($dest4).'">';
}else{
    echo 'create thumb fail';
}


// 按比例生成缩略图,不足部分用#FF0000填充 CMYK格式
$param = array(
    'type' => 'fit',
    'width' => 100,
    'height' => 100,
    'bgcolor' => '#FFFF00'
);

$obj = new PicThumb($logfile);
$obj->set_config($param);
$flag = $obj->create_thumb($source2, $dest5);

if($flag){
    echo '<img src="pic/'.basename($dest5).'">';
}else{
    echo 'create thumb fail';
}


// 裁剪250x250的缩略图,裁剪位置是底部中间,水印位置西南,透明度50 CMYK格式
$param = array(
    'type' => 'crop',
    'croppos' => 'BM',
    'width' => 250,
    'height' => 250,
    'watermark' => $watermark,
    'opacity' => 50,
    'gravity' => 'SouthWest'
);

$obj = new PicThumb($logfile);
$obj->set_config($param);
$flag = $obj->create_thumb($source2, $dest6);

if($flag){
    echo '<img src="pic/'.basename($dest6).'">';
}else{
    echo 'create thumb fail';
}
?>
源文件下载:点击下载

Imagic的用法,代替GD库 一个可以供PHP调用ImageMagick功能的PHP扩展。使用这个扩展可以使PHP具备和ImageMagick相同的功能。   ImageMagick是一套功能强大、稳定而且免费的工具集和开发包,可以用来读、写和处理超过185种基本格式的图片文件,包括流行的TIFF, JPEG, GIF, PNG, PDF以及PhotoCD等格式。利用ImageMagick,你可以根据web应用程序的需要动态生成图片, 还可以对一个(或一组)图片进行改变大小、旋转、锐化、减色或增加特效等操作,并将操作的结果以相同格式或其它格式保存。 立即下载

相关推荐

php实现的支持imagemagick及gd库两种处理的缩略图生成类

本文实例讲述了php实现的支持imagemagick及gd库两种处理的缩略图生成类及其用法实例,非常具有实用价值。分享给大家供大家参考。具体如下: 一、功能: 1.按比例缩小/放大 2.填充背景色 3.按区域裁剪 4.添加水印,包括水印的位置,透明度等 使用imagemagick/GD库实现,imagemagick地址:www.imagemagick.org 需要安装imagemagick,安装方法如下:https://www.jb51.net/article/55528.htm 二、实现方法: PicThumb.class.php类文件如下: <?php /** 缩略图生成类,支持imag

php 根据url自动生成缩略图,并处理高并发问题

服务器生成缩略图的时机一般分为两种: 1.上传文件时生成 优点:上传时就已经生成需要的缩略图,读取时不需要再判断,减少cpu运算。 缺点:当缩略图尺寸变化时或新增尺寸时,需要重新生成所有的缩略图。 2.访问时生成 优点:1.当有用户访问时才需要生成,没有访问的不用生成,节省空间。 2.当修改缩略图尺寸时,只需要修改设置,无需重新生成所有缩略...

weixin_33786077的博客 215

CATIA二次开发CAA安装

安装资料在网盘里 Win7 64位 以下软件均已管理员身份运行: 1.安装vs2008->自定义安装->选择要安装的功能->Visual C+±>x64编译器和工具 1.2安装SP1 2.安装CATIA V5 R21->win7_XP->CATIA.P3.V5R21.Win64->setup.exe 2.1安装目录改为D盘 2.2环境目录位置默认 3.安装...

qq_39311458的博客 4632

分享几个快速自动生成缩略图的api

分享一个快速自动生成缩略图的api https://s0.wp.com/mshots/v1/https://www.rilicx.com?w=600&h=450 目前应该是国内速度比较快的了,做分类目录、网址导航站必备。

ahhnzhao的博客 2941

从东南大学906被刷到调剂过程(内含个人感想)

介绍了自己在看到初试成绩,到后期复习以及调剂的全过程,当中也包含了自己的复试中的感想,希望大家理性看待。

Philo的博客 2856

uniapp - 实现APP后台持续定位+手机息屏后能持续上传位置信息数据,详解后台保活持续运行+手机锁屏保证后台持续/实时定位的解决方案及示例源码(完美兼容安卓android与苹果ios系统手机)

使用uniapp开发app实现后台保活定位能力,uniapp实时定位保活 息屏定位后台运行,uniapp APP实时定位高德 后台运行 支持锁屏息屏运行,持续获取定位信息,uniapp App端后台间隔时间发送定位功能实现,UniApp实现手机应用常活,固定时间内上传手机位置信息,后台(或锁屏)持续/实时定位的实现方案,uni-app后台持续定位,锁屏后能持续上传位置信息,实现后台定位持续无限制定位高德定位,百度定位,UniApp后台持续定位保如何在APP退到后台时保持定位服务,uniapp 切换app仍能

🏆 前端领域优质创作者 1万+

html页面缩略图生成,根据URL自动生成网页缩略图的源代码

一、原理及程序类型原理:通过IE在本地打开目标URL同时截图;本方法存在安全性的问题,千万不要为恶意网页生成缩略图,可能会给您带来一场灾难!程序类型:C#语句(CS结构的程序)。二、源代码private void OnDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e){WebBrowser browser...

weixin_39623271的博客 1408

小秋SLAM入门实战ubuntu所有文章汇总

ubuntu 终端如何停止快速打印的输出以及恢复命令 ubuntu 终端如何快速打开当前路径下的图形化窗口界面? killall -9用途用法 ps -xu | grep这个命令的用途 linux 下 top命令显示的是内存是堆内存吗? zip分割和合并 关闭除当前 GNOME 终端窗口以外的所有其他 GNOME 终端窗口 如何在安装系统后设置短密码 【如何使用getrusage获取消耗的CPU时间和进程使用的最大物理内存】 【webots安装使用教程】 Linux系统下查看当前运行的进程和线程的几种方法

小秋 AI SLAM 入门实战教程 1405

php 缩略图生成类 支持imagemagick及gd库两种处理

php 缩略图生成类 支持imagemagick及gd库两种处理

hsyyff的博客 253

互联网的发展简史—web

互联网是我现在生活所离不开的一个东西,但是你知道互联网的前世今生吗?本文将讲解互联网的发展史,以及很火的元宇宙概念。

yj11290301的博客 3562

【以太网硬件十二】以太网端口自协商过程解密之二

简述以太网端口自协商的过程

highman110的博客 2489

php实现的支持imagemagick及GD库两种处理的缩略图生成类

这篇文章主要介绍了php实现的支持imagemagick及gd库两种处理的缩略图生成类,包含了用法的详细描述,非常实用,需要的朋友可以参考下 一、功能: 1.按比例缩小/放大 2.填充背景色 3.按区域裁剪 4.添加水印,包括水印的位置,透明度等 使用imagemagick/GD库实现,imagemagick地址:www.imagemagick.org

TAKUNHA的博客 619

车载以太网网络测试-27【SOME/IP-SD简述】

SOME/IP-SD协议是基于IP的可扩展面向服务中间件中的服务发现协议,是汽车电子和嵌入式系统中实现动态服务发现与通信的核心组件。该协议规范详细说明了协议SOME/IP服务发现(SOME/IP-SD)的格式、消息序列和语义。本文将对SOME/IP-SD协议进行详细介绍。

车载网络测试工程师的博客 1956

php gd库和imagemagick,php实现的支持imagemagick及gd库两种处理的缩略图生成类

/** 缩略图生成类,支持imagemagick及gd库两种处理* Date: 2013-07-15* Author: fdipzone* Ver: 1.2** Func:* public set_config: 设置参数* public create_thumb: 生成缩略图* private fit: 缩略图片* private crop: 裁剪图片* private g...

weixin_36370851的博客 157

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

php gd库和imagemagick,php实现的支持imagemagick及gd库两种处理的缩略图生成类_PHP

本文实例讲述了php实现的支持imagemagick及gd库两种处理的缩略图生成类及其用法实例,非常具有实用价值。分享给大家供大家参考。具体如下:一、功能:1.按比例缩小/放大2.填充背景色3.按区域裁剪4.添加水印,包括水印的位置,透明度等使用imagemagick/GD库实现,imagemagick地址:www.imagemagick.org需要安装imagemagick,安装方法如下:htt...

weixin_39619451的博客 205

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

php gd crop,php实现的支持imagemagick及gd库两种处理的缩略图生成类

本文实例讲述了php实现的支持imagemagick及gd库两种处理的缩略图生成类及其用法实例,非常具有实用价值。分享给大家供大家参考。具体如下:一、功能:1.按比例缩小/放大2.填充背景色3.按区域裁剪4.添加水印,包括水印的位置,透明度等使用imagemagick/GD库实现,imagemagick地址:www.imagemagick.org需要安装imagemagick,安装方法如下:htt...

weixin_32211137的博客 193

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

php imagemagick及gd库两种图片处理

php imagemagick及gd库两种图片处理

qq_34418823的博客 342

php gd库和imagemagick,php支持imagemagick与gd库缩略图生成类

分享一个php实现的缩略图类,支持imagemagick及gd库两种处理的缩略图生成类,功能包括按区域裁剪图片、添加水印、包括水印功能、透明度等,需要的朋友参考下。php实现同时支持imagemagick及gd库的缩略图生成类与用法。一、功能:1、按比例缩小/放大2、填充背景色3、按区域裁剪4、添加水印,包括水印的位置,透明度等使用imagemagick/GD库实现,imagemagick地址:w...

weixin_35931314的博客 258

php gd库和imagemagick,php 缩略图生成类(支持imagemagick与gd库)

/** 缩略图生成类,支持imagemagick及gd库两种处理* Date: 2013-07-15* Author: fdipzone* Ver: 1.2* edit: bbs.it-home.org* Func:* public set_config: 设置参数* public create_thumb: 生成缩略图* private fit: 缩...

weixin_29932857的博客 132

php-gd 慢,gd-PHP生成图片太慢了。。有些都不出来、

现在为了使用不同宽高的图片,做了个动态生成的程序。每次根据图片传入的宽高来输出图片,然后 html 页面里用这个就是 900X400 的。用也就是 php 的 GD 库来创建个图层,来根据比例重新画出一个图imagecreatetruecolor($_n_w,$_n_h);imagecopyresampled($this->new,$this->img,0,0,$_cut_width,...

weixin_30520605的博客 441

基于ImageMagick的php图片处理库Grafika介绍

基于ImageMagick的php图片处理库Grafika介绍

qq_32421489的博客 2555

搞定PHP图片处理:除了GD库,用PHPStudy+ImageMagick处理PDF和复杂图片的完整流程

本文详细介绍了在PHPStudy环境下配置和使用ImageMagick扩展进行高阶图像处理的全流程。通过对比GD库,展示了ImageMagick在处理PDF、多图合成及复杂格式转换方面的优势,并提供了完整的安装指南、常见问题解决方案及实战案例,帮助开发者高效实现复杂图像处理需求。

weixin_33720956的博客 485

php-gd 慢,gd - PHP生成图片太慢了。。有些都不出来、

现在为了使用不同宽高的图片,做了个动态生成的程序。每次根据图片传入的宽高来输出图片,然后 html 页面里用这个就是 900X400 的。用也就是 php 的 GD 库来创建个图层,来根据比例重新画出一个图imagecreatetruecolor($_n_w,$_n_h);imagecopyresampled($this->new,$this->img,0,0,$_cut_width,...

weixin_39855568的博客 227
上一篇: shell 记录apache status并自动更新到数据库
下一篇: php5.3 中显示Deprecated: Assigning the return value of new by reference is deprecated in 的解决方法
傲雪星枫
博客等级 码龄15年 2307粉丝 306原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值