Hello all,
I followed this tutorial: https://www.youtube.com/watch?v=o6PMaKmCnHg But the code doesn't work very well. I get next issue:
When I upload a image, it will be uploaded as a file and not as a .png. He doesn't upload the images in the 'images/' folder. He upload them in de root folder with the name: $image_name.
I have no idea what I do wrong. I followed your tutorial a few times but I can' t find the solution. Can anybody help me with this (little) error?
My code(S):
image.php
[syntax=php]
<?php
include('core/init.inc.php');
if (isset($_FILES['image'])){
$image_name = 'images/' . md5(microtime(true)) . '.png';
watermark_image($_FILES['image']['tmp_name'], '$image_name');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div>
<?php
?>
</div>
<div>
<form action="" method="post" enctype="multipart/form-data" />
<input type="file" name="image" />
<input type="submit" value="Upload!" />
</form>
</div>
</body>
</html>
[/syntax]
img.inc.php
[syntax=php]
<?php
function watermark_image($image, $output){
$info = @getimagesize($image);
print_r($info);
switch ($info['mime']){
case 'image/jpeg':
$main = imagecreatefromjpeg($image);
break;
case 'image/png':
$main = imagecreatefrompng($image);
break;
case 'image/gif':
$main = imagecreatefromgif($image);
break;
default:
return false;
}
imagealphablending($main, true);
$overlay = imagecreatefrompng("{$GLOBALS['path']}/watermark.png");
imagecopy($main, $overlay, 5, 5, 0, 0, imagesx($overlay), imagesy($overlay));
imagepng($main, $output);
}
?>
[/syntax]
init.inc.php
[syntax=php]
<?php
$path = dirname(__FILE__);
include("{$path}/inc/img.inc.php");
?>
[/syntax]
Result:
So, my map directory:
I hope anybody can help me.
Sorry for my bad English..
Regards,
phpnewby
PHP Tutorial: Watermarking an Image [problems]
Re: PHP Tutorial: Watermarking an Image [problems]
In line 5 of image.php, loose the apostrophe's on $image_name (').
I don't think you need them.
I don't think you need them.
Re: PHP Tutorial: Watermarking an Image [problems]
Hello Helx,
You saved my day! This is working great!
Regards,
php newby
You saved my day! This is working great!
Regards,
php newby