Connecting Tech Pros Worldwide Help | Site Map

embed logo on upload image in php

  #1  
Old June 12th, 2009, 08:35 AM
Familiar Sight
 
Join Date: Aug 2008
Posts: 160
Hey All,

I want to embed logo while upload an image. I mean when i upload an image, i want to embed the logo of the website in that uploaded image.

Kindly help me out to sort out my problems and as i always get a reply from this great community so i believe again i will get the solution of my problem here.

kind regards,
Mohsin Rafique
  #2  
Old June 12th, 2009, 08:57 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,487
Provided Answers: 9

re: embed logo on upload image in php


check out imagecopymerge(). especially the comments.
  #3  
Old June 12th, 2009, 09:04 AM
Familiar Sight
 
Join Date: Aug 2008
Posts: 160

re: embed logo on upload image in php


Thank you very much
I will study n try to do that. As soon as i will do i will be back with that solution
  #4  
Old June 12th, 2009, 09:41 AM
Familiar Sight
 
Join Date: Aug 2008
Posts: 160

re: embed logo on upload image in php


Hey Dormilich,
I found a function from there which is exactly up to my requirement but in my case it is not working and show dirty characters after creating image.

Here is my code i am using for uploading and for watermarking

Expand|Select|Wrap|Line Numbers
  1. $file_extension=strtolower(get_ext($_FILES['photo_1']['name']));
  2. $photo_1="images/cars/".time().'_1.'.$file_extension;
  3. move_uploaded_file($_FILES['photo_1']['tmp_name'],$photo_1);
  4. $imageproduct = new Thumbnail($photo_1, 640, 480, 100);
  5. $imageproduct->save($photo_1);
  6. $watermarklogo="images/logo_png.png";
  7. watermark($photo_1,$watermarklogo);
  8.  

And this is the function i got from there which comes up to my requirement
Expand|Select|Wrap|Line Numbers
  1. function watermark($sourcefile, $watermarkfile) {
  2.         #
  3.         # $sourcefile = Filename of the picture to be watermarked.
  4.         # $watermarkfile = Filename of the 24-bit PNG watermark file.
  5.         #
  6.  
  7.         //Get the resource ids of the pictures
  8.         $watermarkfile_id = imagecreatefrompng($watermarkfile);
  9.  
  10.         imagealphablending($watermarkfile_id, false);
  11.         imageSaveAlpha($watermarkfile_id, true);
  12.  
  13.         $fileType = strtolower(substr($sourcefile, strlen($sourcefile)-3));
  14.  
  15.         switch($fileType) {
  16.             case('gif'):
  17.                 $sourcefile_id = imagecreatefromgif($sourcefile);
  18.                 break;
  19.             case('png'):
  20.                 $sourcefile_id = imagecreatefrompng($sourcefile);
  21.                 break;
  22.             default:
  23.                 $sourcefile_id = imagecreatefromjpeg($sourcefile);
  24.         }
  25.         //Get the sizes of both pix  
  26.         $sourcefile_width=imagesx($sourcefile_id);
  27.         $sourcefile_height=imagesy($sourcefile_id);
  28.         $watermarkfile_width=imagesx($watermarkfile_id);
  29.         $watermarkfile_height=imagesy($watermarkfile_id);
  30.  
  31.         $dest_x = ( $sourcefile_width / 2 ) - ( $watermarkfile_width / 2 );
  32.         $dest_y = ( $sourcefile_height / 2 ) - ( $watermarkfile_height / 2 );
  33.  
  34.         // if a gif, we have to upsample it to a truecolor image
  35.         if($fileType == 'gif') {
  36.             // create an empty truecolor container
  37.             $tempimage = imagecreatetruecolor($sourcefile_width, $sourcefile_height);
  38.                // copy the 8-bit gif into the truecolor image
  39.             imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0, $sourcefile_width, $sourcefile_height);
  40.               // copy the source_id int
  41.             $sourcefile_id = $tempimage;
  42.         }
  43.         imagecopy($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0, $watermarkfile_width, $watermarkfile_height);
  44.         //Create a jpeg out of the modified picture
  45.         switch($fileType) {    
  46.             // remember we don't need gif any more, so we use only png or jpeg.
  47.             // See the upsaple code immediately above to see how we handle gifs
  48.             case('png'):
  49.                 header("Content-type: image/png");
  50.                 imagepng ($sourcefile_id);
  51.                 break;
  52.             default:
  53.                 header("Content-type: image/jpg");
  54.                 imagejpeg ($sourcefile_id);
  55.         }
  56.         imagedestroy($sourcefile_id);
  57.         imagedestroy($watermarkfile_id);
  58.     }
  59.  

kindly help me out to sort out my problem pleaseeeee
  #5  
Old June 12th, 2009, 10:11 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,487
Provided Answers: 9

re: embed logo on upload image in php


any errors, warnings, notices? have you tried with bare/sample images (without uploading) first? did you check the function return values?
  #6  
Old June 12th, 2009, 10:57 AM
Familiar Sight
 
Join Date: Aug 2008
Posts: 160

re: embed logo on upload image in php


Yeh it post and give warning message.
And also show dirty characters in it.

I am attaching the image of it
Attached Thumbnails
error.jpg  
  #7  
Old June 12th, 2009, 11:01 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,487
Provided Answers: 9

re: embed logo on upload image in php


what does the error message say? (too small to read). the error message directly involves the "dirty characters", once you clear the error it should be ok.

EDIT: the "dirty characters" are actually your picture… expressed as string
  #8  
Old June 12th, 2009, 11:03 AM
Familiar Sight
 
Join Date: Aug 2008
Posts: 160

re: embed logo on upload image in php


It is saying that cannot modify header information
Quote:
Warning: Cannot modify header information - headers already sent by (output started at E:\server\htdocs\themosaicdesigns\site\projects\ca rsbay\includes\thumbnail.class.php:423) in E:\server\htdocs\themosaicdesigns\site\projects\ca rsbay\edit-photos.php on line 272
  #9  
Old June 12th, 2009, 11:05 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,487
Provided Answers: 9

re: embed logo on upload image in php


what does
Quote:
output started at E:\server\htdocs\themosaicdesigns\site\projects\ca rsbay\includes\thumbnail.class.php:423
refer to?
  #10  
Old June 12th, 2009, 11:06 AM
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,862
Provided Answers: 9

re: embed logo on upload image in php


Quote:
Originally Posted by neovantage View Post
It is saying that cannot modify header information
On line 423 of E:\server\htdocs\themosaicdesigns\site\projects\ca rsbay\includes\thumbnail.class.php, you have sent output to the browser. You cannot do that if you intend to modify the headers later.
  #11  
Old June 12th, 2009, 11:09 AM
Familiar Sight
 
Join Date: Aug 2008
Posts: 160

re: embed logo on upload image in php


Basically thumbnail.class.php resize my uploaded image.
What i want actually is
i want to upload pictures. Pictures may be large in size so i have to resize them as the client requirement. Now he want that When an image upload then it must be resize and also this process embed his website logo tu the uploaded image and that is what i am trying to do.

i am using thumbnail.class which resize the uploaded image and save it to the required path.

If i even exclude it even then it shows n give me dirty characters and do not embed logo into the uploaded image
  #12  
Old June 12th, 2009, 11:11 AM
Familiar Sight
 
Join Date: Aug 2008
Posts: 160

re: embed logo on upload image in php


So what should i do now.

As i need to upload the image, embed logo into uploaded image, then i need to resize the image and then need to save it
  #13  
Old June 12th, 2009, 11:17 AM
Familiar Sight
 
Join Date: Aug 2008
Posts: 160

re: embed logo on upload image in php


Sir i want that when i upload an image it get that image.
1. Upload it to the server
2. Embed logo into it
3. Resize it too.

These 3 things i want to do

Awaiting of your guideline to do these step by step
  #14  
Old June 12th, 2009, 11:20 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,487
Provided Answers: 9

re: embed logo on upload image in php


first, check what's causing the output in thumbnail.class.php on line 423.
  #15  
Old June 12th, 2009, 11:37 AM
Familiar Sight
 
Join Date: Aug 2008
Posts: 160

re: embed logo on upload image in php


i am attaching the file thumbnail.class.php file as in line 423 there is nothing in it
Attached Files
File Type: zip thumbnail.class.zip (1.8 KB, 5 views)
  #16  
Old June 12th, 2009, 11:50 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,487
Provided Answers: 9

re: embed logo on upload image in php


you have 2 line breaks after the closing "?>", that counts as output–remove them.

you should use "<?php" as start tag, not every system allows short tags.
  #17  
Old June 12th, 2009, 01:05 PM
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,862
Provided Answers: 9

re: embed logo on upload image in php


Quote:
Originally Posted by Dormilich View Post
you have 2 line breaks after the closing "?>", that counts as output–remove them.

you should use "<?php" as start tag, not every system allows short tags.
To prevent accidental output after the closing PHP tag, you can just omit it all together. This is a common practice, and is, I believe, enforced in the Zend Coding Standard.
  #18  
Old June 12th, 2009, 03:30 PM
Familiar Sight
 
Join Date: Aug 2008
Posts: 160

re: embed logo on upload image in php


But my problem is still there.
I still unable to do these 3 tasks simultaneously
1. Upload it to the server
2. Embed logo into it
3. Resize it too.

So what should i do now? i am still there from where i start
  #19  
Old June 13th, 2009, 09:27 AM
Familiar Sight
 
Join Date: Aug 2008
Posts: 160

re: embed logo on upload image in php


Hey Dormilich and Markus,
Hope you are best in health and life. So please guide me what should i do now so that i can upload images, embed logos and resize them simultaneously.

Awaiting of your reply
Mohsin Rafique
  #20  
Old June 13th, 2009, 09:08 PM
n8kindt's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Southern California
Posts: 221

re: embed logo on upload image in php


Quote:
Originally Posted by neovantage View Post
It is saying that cannot modify header information
this is a long thread. i didn't see that you ever cleared this error and it might be the source of your problem. i'm guessing the offending line is trying to send the file type information to the header. you can't do this if you've already sent information to the browser (eg using the function 'echo');

there is a workaround for delaying that information from being sent immediately and still modify the header. try putting ob_start(); on the first line of your php code and ob_get_clean(); on the last line of your php code. you can also read about output buffering here: http://us2.php.net/manual/en/intro.outcontrol.php
  #21  
Old June 14th, 2009, 01:17 PM
Familiar Sight
 
Join Date: Aug 2008
Posts: 160

re: embed logo on upload image in php


my script is uploading picture now and also resizing them. But when i embed logo into the picture it output the embedded log picture into the same window. But how can i overwrite that new picture on the existing picture on the directory path.

Please find the attached images of the output.
Attached Thumbnails
01.jpg   02.jpg  
  #22  
Old June 15th, 2009, 10:40 PM
n8kindt's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Southern California
Posts: 221

re: embed logo on upload image in php


i think this might help you: http://koivi.com/php-gd-image-watermark/

i haven't looked at the available source code but i believe what you need is there. if not, google "php gd watermark"
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
hwo to save a new created image on disk neovantage answers 3 June 15th, 2009 12:45 PM