透かしを入れた後、単一の画像をさまざまなサイズでリストしようとしています。
しかし、画像を保存しようとすると、元のサイズが保存されます。表示されているサイズに応じて画像を保存するにはどうすればよいですか。私を助けてください。私は本当にこれを行う必要があります。
ここに開始コードがあります...
<?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);
$black = imagecolorallocate($image, 0, 0, 0);
$text = imagettftext($imageSource, $fontSize, 0, 20, ($height-20), $black, $font, $watermark);
ob_start();
imagejpeg($imageSource);
$image = ob_get_contents();
ob_end_clean();
return base64_encode($image);
}
?>
<html>
<head>
<title>
Watermark
</title>
<style type="text/css">
body{ width:800px; margin: 15px auto; padding:0px; font-family: arial}
.box
{
border:5px solid #808080;
border-radius:25px;
padding: 10px;
background-color: #E6E6FA;
font-family: courier;
src: url('courier.ttf');
}
</style>
</head>
<body>
<div> <img src="top.png" style="position:absolute;top:0px;left:0px;height:100px;width:100%;" /> </div>
<br /> <br />
<img src="logo.png" style="position:absolute;top:30px;" /> <br /> <br />
</div>
<br /> <br />
<div align="justify" class="box">
<strong>Banner Creator</strong> is a simple, yet awesome, way to create banners for your website, social networking profiles (including FB banners)
online advertising or simply for promoting of your business or event. Banner Creator is popular with online businesses,
webmasters and anyone else who uses the web to promote there message be it via email or social media such as people on Facebook and Myspace.
</div> <br />
<div class="box"> <strong> How to use : </strong> <br>
* Upload any image <br>
* Add any text (optional) <br>
* Right-click on the desired image and click 'Save Image As' <br />
</div>
<form name="imageUpload" id="imageUpload" method="post" enctype="multipart/form-data" > <fieldset>
<legend> <h1>upload your image</h1></legend>
<strong>Image:</strong> <input type="file" name="image" id="image"/>
<strong> Text: </strong> <input type="text" name="text" id="text"/>
<input type="checkbox" name="boxshadow" value="Bike">Apply Box-Shadow<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)
{
if ( isset( $_POST['boxshadow'] ) ) {
echo " <center><img src='output.png' /></center> <br/>";
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES['image']['tmp_name'], $_POST['text'], 30, "./arial.ttf") . "\" style='position:absolute;left:320px;top:600px;width:728px;height:90px;box-shadow: 10px 10px 5px #888888;'/>";
echo "<div style='position:absolute;left:550px;top:695px;'>Leaderboard/Default Banner (728x90)</div>";
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES['image']['tmp_name'], $_POST['text'], 30, "./arial.ttf") . "\" style='position:absolute;left:530px;top:740px;width:250px;height:300px;box-shadow: 10px 10px 5px #888888;'/>";
echo "<div style='position:absolute;left:550px;top:1045px;'>Medium Rectangle (300x250) </div>";
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES['image']['tmp_name'], $_POST['text'], 30, "./arial.ttf") . "\" style='position:absolute;left:535px;top:1090px;width:250px;height:250px;box-shadow: 10px 10px 5px #888888;'/>";
echo "<div style='position:absolute;left:600px;top:1345px;'>Square Pop-Up (250x250) </div>";
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES['image']['tmp_name'], $_POST['text'], 30, "./arial.ttf") . "\" style='position:absolute;left:550px;top:1390px;width:240px;height:400px;box-shadow: 10px 10px 5px #888888;'/>";
echo "<div style='position:absolute;left:600px;top:1795px;'>Vertical Rectangle (240x400)</div>";
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES['image']['tmp_name'], $_POST['text'], 30, "./arial.ttf") . "\" style='position:absolute;left:530px;top:1840px;width:336px;height:280px;box-shadow: 10px 10px 5px #888888;'/>";
echo "<div style='position:absolute;left:600px;top:2130px;'>Large Rectangle (336x280) </div>";
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES['image']['tmp_name'], $_POST['text'], 30, "./arial.ttf") . "\" style='position:absolute;left:600px;top:2220px;width:180px;height:150px;box-shadow: 10px 10px 5px #888888;'/>";
echo "<div style='position:absolute;left:600px;top:2375px;'>Rectangle (180x150)</div>";
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES['image']['tmp_name'], $_POST['text'], 30, "./arial.ttf") . "\" style='position:absolute;left:540px;top:2420px;width:300px;height:100px;box-shadow: 10px 10px 5px #888888;'/>";
echo "<div style='position:absolute;left:600px;top:2525px;'>3:1 Rectangle (300x100) </div>";
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES['image']['tmp_name'], $_POST['text'], 30, "./arial.ttf") . "\" style='position:absolute;left:460px;top:2570px;width:468px;height:60px;box-shadow: 10px 10px 5px #888888;'/>";
echo "<div style='position:absolute;left:600px;top:2635px;'>Full Banner (468x60) </div>";
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES['image']['tmp_name'], $_POST['text'], 30, "./arial.ttf") . "\" style='position:absolute;left:570px;top:2680px;width:234px;height:60px;box-shadow: 10px 10px 5px #888888;'/>";
echo "<div style='position:absolute;left:600px;top:2745px;'>Half Banner (234x60)</div>";
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES['image']['tmp_name'], $_POST['text'], 30, "./arial.ttf") . "\" style='position:absolute;left:620px;top:2790px;width:88px;height:31px;box-shadow: 10px 10px 5px #888888;'/>";
echo "<div style='position:absolute;left:620px;top:2826px;'>Micro (88x31)</div>";
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES['image']['tmp_name'], $_POST['text'], 30, "./arial.ttf") . "\" style='position:absolute;left:600px;top:2871px;width:120px;height:90px;box-shadow: 10px 10px 5px #888888;'/>";
echo "<div style='position:absolute;left:600px;top:2965px;'>Button 1 (120x90)</div>";
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES['image']['tmp_name'], $_POST['text'], 30, "./arial.ttf") . "\" style='position:absolute;left:600px;top:3011px;width:120px;height:60px;box-shadow: 10px 10px 5px #888888;'/>";
echo "<div style='position:absolute;left:600px;top:3076px;'>Button 2 (120x60)</div>";
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES['image']['tmp_name'], $_POST['text'], 30, "./arial.ttf") . "\" style='position:absolute;left:600px;top:3121px;width:120px;height:240px;box-shadow: 10px 10px 5px #888888;'/>";
echo "<div style='position:absolute;left:600px;top:3366px;'>Vertical Banner (120x240)</div>";
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES['image']['tmp_name'], $_POST['text'], 30, "./arial.ttf") . "\" style='position:absolute;left:600px;top:3411px;width:120px;height:125px;box-shadow: 10px 10px 5px #888888;'/>";
echo "<div style='position:absolute;left:600px;top:3541px;'>Square Button (120x125)</div>";
echo "<img src=\"data:image/gif;base64," . renderImage($_FILES['image']['tmp_name'], $_POST['text'], 30, "./arial.ttf") . "\" style='position:absolute;left:600px;top:3586px;width:120px;height:600px;box-shadow: 10px 10px 5px #888888;'/>";
echo "<div style='position:absolute;left:600px;top:4191px;'>Skyscrapper (120x600)</div>";