【php图片的裁剪与缩放生成符合需求的缩略图_PHP】教程文章相关的互联网学习教程文章

php上传图片生成缩略图

function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $quality){ $details = getimagesize("$imageDirectory/$imageName") or die('Please only upload images.'); $type = preg_replace('@^.+(? eval('$srcImg = imagecreatefrom'.$type.'("$imageDirectory/$imageName");'); $thumbHeight = $details[1] * ($thumbWidth / $details[0]); $thumbImg = imagecreatetruecolor...

图片上传并使用ImageMagick生成缩略图【图】

使用ImageMagick,您可以轻松,更快地创建缩略图,比使用PHP的容易得多。 // Location to upload main image:$mainDir = $_SERVER['DOCUMENT_ROOT'].'/images/l/';// Location to create the thumb image:$smalDir = $_SERVER['DOCUMENT_ROOT'].'/images/s/';// Command to use:$command = '/usr/bin/convert';// Thumbnail width:$size = 210;// Make sure we have an image:if(isset($_POST['submit'])){ if(getimagesize($_...

PHP图片上传类并生成缩略图

/*** 上传图片*/class imgUpload{ static protected $a; protected $formName; //表单名称 protected $directory; //文件上传至目录 protected $maxSize; //最大文件上传大小 protected $canUpload; //是否可以上传 protected $doUpFile; //上传的文件名 protected $sm_File; //缩略图名称 private ...

PHP图片上传并生成缩略图类

/*** 上传图片*/class imgUpload{ static protected $a; protected $formName; //表单名称 protected $directory; //文件上传至目录 protected $maxSize; //最大文件上传大小 protected $canUpload; //是否可以上传 protected $doUpFile; //上传的文件名 protected $sm_File; //缩略图名称 private ...

php生成图像缩略图(支持:JPEG,GIT,PNG,BMP)

<?phpclass Thumb{ public function create($srcPath, $dstPath, $dstWidth, $dstHeight) { if (!file_exists($srcPath)) { return false; } @$srcSize = getimagesize($srcPath); if (empty($srcSize)) { return false; } $srcWith = intval($srcSize[0]); $srcHeight = intval($srcSize[1]); //如果原始图片的尺寸大于指定缩略图的尺寸,则...

实现缩略图和加水印的php类

/** * 图片缩放水印类 * * @version 1.0 ; * */class cls_photo{ protected $waterrate = 0.2; //水印图标在图片上的比例 protected $width = 300; //缩略图默认宽度 protected $height = 200; //缩略图默认高度 protected $padding = 5; //水印图到边的距离 protected $water_mark = "./water.png"; protected $water_mark_pos = 5;//水印图片位置(1=左上角,2=右上角,3=左下角,4=右下角,5中央) protec...

php生成图片缩略图代码类

生成多种类型的缩略图 /****************************************作者:落梦天蝎(beluckly)*完成时间:2006-12-18*类名:CreatMiniature*功能:生成多种类型的缩略图*基本参数:$srcFile,$echoType*方法用到的参数: $toFile,生成的文件 $toW,生成的宽 $toH,生成的高 $bk1,背景颜色参数 以255为最高 $bk2,背景颜色参数 $bk3,背景颜...

php生成缩略图代码

/***********************@filename - path to the image*@tmpname - temporary path to thumbnail*@xmax - max width*@ymax - max height*/function resize_image($filename, $tmpname, $xmax, $ymax){ $ext = explode(".", $filename); $ext = $ext[count($ext)-1]; if($ext == "jpg" || $ext == "jpeg") $im = imagecreatefromjpeg($tmpname); elseif($ext == "png") $im = imagecreatefrompng($tm...

PHP图片处理函数类(水印图,缩略图)[关于等比例压缩与裁剪压缩]

下面简单的写了一个图片处理类,功能包括:水印,缩略图等。不过,对于生成缩略图有两种方式:一种是直接按比例来压缩图片,另外一种是先裁剪再压缩的方式。在自己看来等例压缩与裁剪压缩区别就在于:等例压缩:能保证图片的宽长比例合理,且图片有完整性。但实际大小不保证符合要求。裁剪压缩: 能保证图片的宽长比例合理,实际大小也能保证。但图片完整性不能保证。 image.php <?php/** * * 图像处理类 * @author FC_LAMP * @int...

用PHP批量生成图片缩略图

function mkdirs($dirname,$mode=0777) //创建目录(目录, [模式]) { if(!is_dir($dirname)) { mkdirs($dirname,$mode); //如果目录不存在,递归建立 return mkdir($dirname,$mode); } return true; } function savefile($filename,$content='') //保存文件(文件, [内容]) { if(function_exists(file_put_contents)) { file_...

php利用GD库生成缩略图

<?php header("content-type:text/html;charset=gbk"); ini_set("date.timezone","Asia/chong"); //判断文件是否为空 if(empty($_FILES)){ echo"上传文件过大"; exit; } //判断文件上传是否有错误 if($_FILES[pic][error]){ echo "上传文件"; exit; } //判断文件类型是否非法获取文件后缀 $allowtype=array("jpg","png","jpeg","gif"); ...

php使用GD创建保持宽高比的缩略图

/** * Create a thumbnail image from $inputFileName no taller or wider than * $maxSize. Returns the new image resource or false on error. * Author: mthorn.net */ function thumbnail($inputFileName, $maxSize = 100) { $info = getimagesize($inputFileName); $type = isset($info[type]) ? $info[type] : $info[2]; // Check support of file type if ( !(imag...

PHP添加水印&amp;amp;比例缩略图&amp;amp;固定高度&amp;amp;固定宽度类。

//PHP 添加水印 & 比例缩略图 & 固定高度 & 固定宽度 类。 class Image_process{ public $source; //原图 public $source_width; //原图宽度 public $source_height; //原图高度 public $source_type_id; public $orign_name; public $orign_dirname; //传入原图路径 public function __construct($source){ $this->typeList = array(1=>'gif',2=>'jpg',3=>'png'); ...

PHP提取页面第一张图为缩略图的代码【图】

$p = '//i;preg_match_all($p,$str,$match);print_r($match[1][0]);?>结果为:http://usr.im/200x60?bg=3498DB&text=tool.lu 结果为: 图为, 第一张, PHP

生成缩略图_PHP教程

生成缩略图$tx=GetImageSize($sample); if($tx[0]=120){ $height=120; $width=intval($height*$tx[0]/$tx[1]); } if($tx[0]>=$tx[1] and $tx[0]>=100){ $width=100; $height=intval($width*$tx[1]/$tx[0]); } if($tx[0] $width=$tx[0]; $height=$tx[1]; } makethumb2($sample,$target,$width,$height); // $srcFile: 源文件 // $dstFile: 目标文件 // $dstW: 目标图片宽度 // $dstH: 目标文件高...