我有以下代码从DB加载图像。已经有超过600行图像插入到DB中。我需要可以执行这些操作的脚本:
步骤1)从DB加载图像 步骤2)通过放置水印来处理图像 步骤3)将图像输出到浏览器。
我有以下代码,加载并显示图像。但我不知道如何做水印。
$dbconn = @mysql_connect($mysql_server,$mysql_manager_id,$mysql_manager_pw) or exit("SERVER Unavailable");
@mysql_select_db($mysql_database,$dbconn) or exit("DB Unavailable");
$sql = "SELECT type,content FROM upload WHERE id=". $_GET["imgid"];
$result = @mysql_query($sql,$dbconn) or exit("QUERY FAILED!");
$contenttype = @mysql_result($result,0,"type");
$image = @mysql_result($result,0,"content");
header("Content-type: $contenttype");
echo $image;
mysql_close($dbconn);
?>
请帮忙......
答案 0 :(得分:1)
你可以通过php.net学习如何自己操作图像,或者只是得到如下所示的包: http://pear.php.net/package/Image_Tools (常见图像处理的工具集合。可用的扩展名为Blend,Border,Marquee,Mask,Swap,Thumbnail和 Watermark 。)
答案 1 :(得分:0)
如何以与SELECT类型内容相同的方式调用图像?
从数据库中选择带有imagepath的图像,然后对其进行样式设置,使其浮动在您的信息上。您也可以对水印图像进行硬编码,因为它始终是您可以重复的相同图像。您不会看到您的信息,但如果您在图像上添加了不透明度,则可以看到它:
#img.watermark {
float:left;
opacity:0.1;
z-index:1;
}
这只是关于如何做到这一点的一个想法,但应该很好地工作!
答案 2 :(得分:0)
答案 3 :(得分:0)
最后我得到了解决方案,这里是代码:
<?php
$dbconn = @mysql_connect($mysql_server,$mysql_manager_id,$mysql_manager_pw) or exit("SERVER Unavailable");
@mysql_select_db($mysql_database,$dbconn) or exit("DB Unavailable");
$sql = "SELECT id, original_name, type, content FROM upload WHERE id=". $_GET["imgid"];
$result = @mysql_query($sql,$dbconn) or exit("QUERY FAILED!");
$fileID = @mysql_result($result,0,"id");
$contenttype = @mysql_result($result,0,"type");
$filename = @mysql_result($result,0,"original_name");
$image = @mysql_result($result,0,"content");
$fileXtension = pathinfo($filename, PATHINFO_EXTENSION);
$finalFileName = $fileID.".".$fileXtension;
// put the file on temporary folder
$filePutPath = "/your/temporary/folder/".$finalFileName;
// put the contents onto file system
file_put_contents($filePutPath, $image);
// get the watermark image
$stamp = imagecreatefrompng('../images/watermark.png');
switch($fileXtension)
{
case 'JPEG':
case 'JPG' :
case 'jpg' :
case 'jpeg':
$im = imagecreatefromjpeg($filePutPath);
break;
case 'gif' :
case 'GIF' :
$im = imagecreatefromgif($filePutPath);
break;
case 'png' :
case 'PNG' :
$im = imagecreatefromgif($filePutPath);
break;
default :
break;
}
list($width, $height) = getimagesize($filePutPath);
// set area for the watermark to be repeated
imagecreatetruecolor($width, $height);
// Set the tile (Combine the source image and the watermark image together)
imagesettile($im, $stamp);
// Make the watermark repeat the area
imagefilledrectangle($im, 0, 0, $width, $height, IMG_COLOR_TILED);
header("Content-type: $contenttype");
// free the memory
imagejpeg($im);
imagedestroy($im);
// delete the file on temporary folder
unlink($filePutPath);
mysql_close($dbconn);
?>