我正在尝试将不同类别的图像保存在一个文件夹中并检索它们..当我保存图像时,水印会自动应用于图像..为此我正在使用。
<?php
if(isset($_POST['submit'])){
$cat=$_POST['cat'];
$fname= $_FILES["file"]["name"];
"Type: " . $_FILES["file"]["type"] . "<br />";
"Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
"stored in: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
"Stored in: " . "upload/" . $_FILES["file"]["name"];
echo 'image Save Successfully' ;
require_once( "watermark.php" );
$original_directory = "upload/";
$watermarked_images = "temp/";
if ($handle = opendir($original_directory))
{
while (false !== ($file = readdir($handle)))
{
if(!is_file($original_directory.$file))
continue;
if(exif_imagetype($original_directory.$file)==2)
{
watermark($original_directory.$file,"watermark.png",$watermarked_images.$file);
//echo "Done watermarking <b>".$file."</b><br>\n";
}
}
closedir($handle);
}
}
}
?>
和 watermark.php 是
<?php
function watermark($original_image,$original_watermark,$destination="")
{
$image=imagecreatefromjpeg($original_image);
list($imagewidth,$imageheight)=getimagesize($original_image);
$watermark = imagecreatefrompng($original_watermark);
list($watermarkwidth,$watermarkheight)=getimagesize($original_watermark);
if($watermarkwidth>$imagewidth || $watermarkheight>$imageheight)
{
$water_resize_factor = $imagewidth / $watermarkwidth;
$new_watermarkwidth = $watermarkwidth * $water_resize_factor;
$new_watermarkheight = $watermarkheight * $water_resize_factor;
$new_watermark = imagecreatetruecolor($new_watermarkwidth , $new_watermarkheight);
imagealphablending($new_watermark , false);
imagecopyresampled($new_watermark , $watermark, 0, 0, 0, 0, $new_watermarkwidth, $new_watermarkheight, $watermarkwidth, $watermarkheight);
$watermarkwidth = $new_watermarkwidth;
$watermarkheight = $new_watermarkheight;
$watermark = $new_watermark;
}
$startwidth = ($imagewidth - $watermarkwidth) / 2;
$startheight = ($imageheight - $watermarkheight) / 2;
imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
if(!empty($destination))
imagejpeg($image,$destination);
else
imagejpeg($image);
}
?>
一些图像保存在上传文件夹和临时文件夹和数据库中,并且在它们上应用了水印..但是现在当我尝试上传图像时..它只在上传文件夹中并且显示致命错误:-
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 15000 bytes) in D:\xampp\htdocs\looks\admin\watermark.php on line 28
我该如何解决这个问题..而且.PNG图像也没有保存