2010-04-24 62 views

回答

3

一种方式做到这一点是使用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)) { 

... 
+0

真棒。我会稍微等待一个答案,表明尽可能的裸露骨骼代码,但这是接受答案的候选人。谢谢。 – henrijs 2010-04-24 01:59:51

+0

不知道它会比这更光秃秃的骨头,如果是这样,我会对它感兴趣;) – 2010-04-24 03:25:54