[英]How to add Watemark logo in a GIF image?
嗨,我想創建水印GIF圖像。
請檢查我的代碼:
func.php
<?php
function allowed_image($file_name){
$allow_set = array('gif','GIF');
$file_ext = (explode('.', $file_name));
$end = end($file_ext);
return (in_array($end , $allow_set) === true) ? true : false;
}
function watermark_image($file, $destination){
$watermark = imagecreatefrompng('logo.png');
$source = getimagesize($file);
$source_mime = $source['mime'];
image = imagecreatefromgif($file);
imagecopy($image, $watermark, 70, 160, 0, 0, imagesx($watermark),imagesy($watermark));
imagepng($image, $destination);
imagedestroy($image);
imagedestroy($watermark);
}
?>
test.php
<?php
include('func.php');
if (isset($_FILES['image'])){
$file_name = $_FILES['image']['name'];
$file_tmp = $_FILES['image']['tmp_name'];
$name = explode('.', $file_name);
if (allowed_image($file_name) === true){
$file_name = time() .'.gif';
watermark_image($file_tmp, 'upload/' . $file_name);
} else{
echo '<p>Please upload only gif image.</p>';
}
}
?>
<form enctype="multipart/form-data" method="post">
<input type="file" name="image" /><input type="submit" value="Go" name="submit" />
</form>
上面的代碼正在工作。 但是問題是當我上傳GIF圖像時,它會創建水印圖像,但GIF圖像沒有動畫。
任何人都可以幫助我。如何用動畫GIF創建水印圖像?
好吧, PHP手冊明確指出:
注意:將動畫GIF文件讀入內存時,圖像資源指針中僅返回第一幀。
在該頁面上的注釋之一中,有人提到http://www.gdenhancer.com/是可用於動畫gif的一個很好的選擇。 我自己沒有任何經驗。
經過大量研究,最終我得到了制作水印gif圖像的解決方案。
您需要imagick和magickwand
試試下面的代碼,它將對您有所幫助:
exec("/usr/local/bin/convert mygif.gif null: watermark-logo.png -gravity SouthEast -layers composite -layers optimize mygif.gif 2>&1",$out,$returnval);
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.