hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : PHP watermarking - need little help.
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

PHP watermarking - need little help.

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 07-22-2008, 11:58 AM
Martinss Martinss is offline
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?

Reply With Quote


Sponsored Links
  #2  
Old 07-23-2008, 06:57 AM
Martinss Martinss is offline
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);



?>

Reply With Quote
  #3  
Old 07-23-2008, 07:02 AM
01globalnet 01globalnet is offline
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

__________________
redeem.gr : Discount Coupons, Deals, Bonus Points
ccp-ebikes.com : Electric Bikes Greece


Reply With Quote
Sponsored Links
Reply

Related posts from TheWhir.com
Title Type Date Posted


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?