我想顯示一個上傳的圖像,隨着文本水印不同大小使用php圖像魔術師沒有保存圖像。圖像調整大小使用php圖像魔術師
這裏是代碼:
<?php
$errors = array();
function mimeValidator($imagefile)
{
$imageInfo = getimagesize($imagefile);
$allowedMimes = array('image/jpg', 'image/jpeg', 'image/png');
if(!in_array($imageInfo['mime'], $allowedMimes))
$errors[] = "Only jpg and png images are supported";
}
function renderImage($imageSource, $watermark, $fontSize, $font)
{
$imageInfo = getimagesize($imageSource);
list($width,$height) = getimagesize($imageSource);
if($imageInfo['mime'] == 'image/jpg' || $imageInfo['mime'] == 'image/jpeg')
$imageSource = imagecreatefromjpeg($imageSource);
elseif($imageInfo['mime'] == 'image/png')
$imageSource = imagecreatefrompng($imageSource);
$image = imagecreatetruecolor($width, $height);
$blue = imagecolorallocate($image, 79, 166, 185);
$text = imagettftext($imageSource, $fontSize, 0, 20, ($height-20), $blue, $font, $watermark);
ob_start();
imagejpeg($imageSource);
$image = ob_get_contents();
ob_end_clean();
return base64_encode($image);
}
?><html>
<head>
<title>
image Watermark and resize
</title>
<style type="text/css">
body{ width:800px; margin: 15px auto; padding:0px; font-family: arial}
</style>
</head>
<body>
<form name="imageUpload" id="imageUpload" method="post" enctype="multipart/form-data" >
<fieldset>
<legend>Image text watermark</legend>
Text: <input type="text" name="text" id="text"/><br />
Image: <input type="file" name="image" id="image"/><br />
<input type="submit" name="submit" id="createmark" value="Submit" />
</fieldset>
<?php
if(isset($_POST['submit']))
{
if($_POST['text'] == '')
$errors[] = "Text is too short";
if($_FILES['image']['tmp_name'] == '')
$errors[] = "Please upload a image";
else
mimeValidator($_FILES['image']['tmp_name']);
if(count($errors) == 0)
{
include('php-image-magician/php_image_magician.php');
$magicianObj = new imageLib($_FILES["image"]["tmp_name"]);
$magicianObj -> resizeImage(100, 200);
$magicianObj -> saveImage($imagename);
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES["image"]["tmp_name"], $_POST['text'], 30, "./arial.ttf") . "\" />";
}
else
{
echo "<ul>";
foreach($errors as $error)
echo "<li>{$error}</li>";
echo "</ul>";
}
}
?>
</form>
</body>
</html>
我得到一個錯誤 「的文件C:\ XAMPP \ tmp目錄\ php9E3D.tmp缺失或無效」 我在這一個newbee。請幫幫我。
良好的呼叫!可以提供有很多調整大小的PHP腳本,這些腳本寫得很好。只需做一個簡單的Google搜索。 – OptimusCrime