
07-22-2008, 11:58 AM
|
|
Newbie
|
|
Join Date: Jan 2008
Posts: 11
|
|
PHP watermarking - need little help.
Hello there!
My PHP skills are very poor, i'm trying to merge this two scripts for hours now. Can somebody merge them?
Code:
<?
include "config.php";
if (!isset($HTTP_POST_FILES['userfile'])) exit;
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
if ($HTTP_POST_FILES['userfile']['size']>$max_size) {
echo "<center><br><br><br>Fails ir parak liels, ludzu samazini to!</center>"; exit; }
if(($HTTP_POST_FILES['userfile']['type']=="image/gif") ||
($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) {
if (file_exists("./".$path . $HTTP_POST_FILES['userfile']['name'])) {
echo "<center><br><br><br>Bilde ar shadu nosaukumu jau eksistee! Nomaini nosaukumu un meegjini veelreiz!</center>"; exit; }
//generate random number
$zufall = time();
$fupl = "$zufall";
$nosaukums = $HTTP_POST_FILES['userfile']['name'];
$ext = substr(strrchr($nosaukums, '.'), 1);
$punkc = ".";
if (file_exists("./".$path .$fupl .$punkc .$ext)) {
echo "<center><br><br><br>Bilde ar shadu nosaukumu jau eksistee! Nomaini nosaukumu un meegjini veelreiz!</center>"; exit; }
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], "./".$path .$fupl .$punkc .$ext);
if (!$res) { echo "<center><br><br><br>Bilde ar shadu nosaukumu jau eksistee! Nomaini nosaukumu un meegjini veelreiz!</center>"; exit; } else {
?>
<br>
<?
//set url variable
$domst = "";
$drecks = "/";
$imgf = $fupl.$punkc.$ext;
$thbf = $tpath.$imgf;
$urlf = $domst .$domain .$drecks .$path .$imgf;
//create thumbnails
function createthumb($name,$filename,$new_w,$new_h){
$system=explode('.',$name);
if (preg_match('/jpg|jpeg|JPG/',$system[1])){
$src_img=imagecreatefromjpeg($name);
}
if (preg_match('/png|PNG/',$system[1])){
$src_img=imagecreatefrompng($name);
}
if (preg_match('/gif|GIF/',$system[1])){
$src_img=imagecreatefromgif($name);
}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y) {
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y) {
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if (preg_match("/png/",$system[1]))
{
imagepng($dst_img,$filename);
}
if (preg_match("/gif/",$system[1]))
{
imagegif($dst_img,$filename);
}
else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
createthumb($path.$imgf,$tpath.$imgf,$tsize,$tsize);
?>
and this
Code:
$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = imagecreatefromjpeg($_GET['src']);
$size = getimagesize($_GET['src']);
$dest_x = $size[0] - $watermark_width - 5;
$dest_y = $size[1] - $watermark_height - 5;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
Basicly it needs to watermark the little thumbnail. Any help? 
|

07-23-2008, 06:57 AM
|
|
Newbie
|
|
Join Date: Jan 2008
Posts: 11
|
|
Any help there?  I've have made this, but a lot of errors.
Code:
<?
//set url variable
$domst = "";
$drecks = "/";
$imgf = $fupl.$punkc.$ext;
$thbf = $tpath.$imgf;
$urlf = $domst .$domain .$drecks .$path .$imgf;
//create thumbnails
function createthumb($name,$filename,$new_w,$new_h){
$system=explode('.',$name);
if (preg_match('/jpg|jpeg|JPG/',$system[1])){
$src_img=imagecreatefromjpeg($name);
}
if (preg_match('/png|PNG/',$system[1])){
$src_img=imagecreatefrompng($name);
}
if (preg_match('/gif|GIF/',$system[1])){
$src_img=imagecreatefromgif($name);
}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y) {
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y) {
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if (preg_match("/png/",$system[1]))
{
imagepng($dst_img,$filename);
}
if (preg_match("/gif/",$system[1]))
{
imagegif($dst_img,$filename);
}
else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
createthumb($path.$imgf,$tpath.$imgf,$tsize,$tsize);
$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$imagems = imagecreatetruecolor($watermark_width, $watermark_height);
$imagems = imagecreatefromjpeg($imgf);
$sizems = getimagesize($imgf);
$dest2_x = $sizems[0] - $watermark_width - 5;
$dest2_y = $sizems[1] - $watermark_height - 5;
imagecopymerge($imagems, $watermark, $dest2_x, $dest2_y, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($imagems);
imagedestroy($imagems);
imagedestroy($watermark);
?>
|

07-23-2008, 07:02 AM
|
|
Web Hosting Master
|
|
Join Date: Mar 2005
Location: Athens, Greece
Posts: 1,484
|
|
Too much code and would need quite of time for anyone to find out what is happening
You can have a look at a wondeful class upload - it handles common image functions very easily.
http://www.verot.net/php_class_upload_download.htm
Quote:
* It manages file uploads for you. In short, it manages the uploaded file,
* and allows you to do whatever you want with the file, especially if it
* is an image, and as many times as you want.
*
* It is the ideal class to quickly integrate file upload in your site.
* If the file is an image, you can convert, resize, crop it in many ways.
* You can also apply filters, add borders, text, watermarks, etc...
* That's all you need for a gallery script for instance.
*
* You can also use the class to work on local files, which is especially
* useful to use the image manipulation features
|
|
Related posts from TheWhir.com
|
| Title |
Type |
Date Posted |
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|