【发布时间】:2011-02-11 18:22:10
【问题描述】:
【问题讨论】:
【问题讨论】:
一种方法是使用 phpThumb。
这里的基本参考:http://phpthumb.sourceforge.net/demo/demo/phpThumb.demo.demo.php#x31
如果动态创建新图像,那么简单如下:
<img src="../phpThumb.php?src=path/to/image/image.jp&fltr[]=mask|path/to/mask/mask.png&f=png" alt="">
输出到png。
如果在上传图片后创建一个新的图片存储在服务器上,首先弄清楚phpThumb的基础知识,然后设置掩码参数和其余的:
例如:
...
require_once('phpThumb/phpthumb.class.php');
//Begin phpThumb work to resize image and create thumbnail
$uploaddir = $_SERVER['DOCUMENT_ROOT'] . $destination;
$uploadfile = $uploaddir . $file;
$phpThumb = new phpThumb();
// set data source -- do this first, any settings must be made AFTER this call
$phpThumb->setSourceFilename($uploadfile);
$phpThumb->setParameter('w', 360); //change to update the picture size
$phpThumb->setParameter('h', 470); //change to update the picture size
$phpThumb->setParameter('fltr[]', 'mask|path/to/mask/mask.png'); //set mask
$phpThumb->setParameter('f', 'png'); //set png output format
$outputdir = $_SERVER['DOCUMENT_ROOT'] . $destination;
$output_filename = $outputdir . "masked" . $file;
$phpThumb->setParameter('config_allow_src_above_docroot', true);
if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
if ($phpThumb->RenderToFile($output_filename)) {
...
【讨论】: