WaterMark - Dong dau anh bang PHP

Cỡ chữ: Decrease font Enlarge font

Qui trình :
- Dùng 1 file hình có nền trong suốt đè lên file hình cần tạo watermark .
- PHP có các hàm để xử lý với ảnh http://vn2.php.net/manual/en/ref.image.php

Code:
<?php

$imagesource "images.jpg"// dia chi hinh
if (!file_exists($imagesource)) die();
$filetype strtolower(substr($imagesource,strlen($imagesource)-4,4));
if($filetype == ".gif"$image = @imagecreatefromgif($imagesource);
if($filetype == ".jpg"$image = @imagecreatefromjpeg($imagesource);
if($filetype == ".png"$image = @imagecreatefrompng($imagesource);
if (empty($image)) die();
$watermark = @imagecreatefromgif('watermark.gif'); // file watermark
$imagewidth imagesx($image);
$imageheight imagesy($image);
$watermarkwidth imagesx($watermark);
$watermarkheight imagesy($watermark);
$startwidth = (($imagewidth $watermarkwidth)/2);
$startheight = (($imageheight $watermarkheight)/2);
imagecopy($image$watermark,  $startwidth$startheight00$watermarkwidth$watermarkheight);
header("Content-type: image/jpeg");
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
?> 

Nếu cảm thấy tự viết quá khó bãn có thể dùng library có sẵn này để làm cho đơn giản hơn và dễ customize hơn: http://wideimage.sourceforge.net/

Tags: ,

Add to: Add to your del.icio.us Digg this story Add to your Twitter Add to your Google Bookmark Add to your Facebook Add to your MySpace
Số lượt xem: 773
trung hieu on August 16th, 2009, 4:06 pm

ko bit nói gì ! Thanks một cái thoy ! bài viết rất bổ ích !

huynh minh le on April 27th, 2010, 9:27 am

bao loi nhu the doa

Warning: mysql_query() [function.mysql-query]: Access denied for user ‘ODBC’@'localhost’ (using password: NO) in C:\AppServ\www\diaocvina\online.php on line 6

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\AppServ\www\diaocvina\online.php on line 6
Access denied for user ‘ODBC’@'localhost’ (using password: NO)

huỳnh đức lợi on July 12th, 2010, 5:55 pm

Warning: mysql_query() [function.mysql-query]: Access denied for user ‘ODBC’@’localhost’ (using password: NO) in C:\AppServ\www\diaocvina\online.php on line 6
=========> chưa có kết nối với cơ sỡ dữ liệu mà bạn tao ra đó

$server = ‘localhost’;
$username = ‘root’;
$password = ”;
$database = ‘db_online_couter’;// tên databate mà bạn tạo
mysql_connect(”$server”, “$username”, “$password”);

Gửi nhận xét:comment

 *
 *