embed logo on upload image in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neovantage
    New Member
    • Aug 2008
    • 245

    embed logo on upload image in php

    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
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    check out imagecopymerge( ). especially the comments.

    Comment

    • neovantage
      New Member
      • Aug 2008
      • 245

      #3
      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

      Comment

      • neovantage
        New Member
        • Aug 2008
        • 245

        #4
        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

        Code:
        $file_extension=strtolower(get_ext($_FILES['photo_1']['name']));
        $photo_1="images/cars/".time().'_1.'.$file_extension;
        move_uploaded_file($_FILES['photo_1']['tmp_name'],$photo_1);
        $imageproduct = new Thumbnail($photo_1, 640, 480, 100);
        $imageproduct->save($photo_1);
        $watermarklogo="images/logo_png.png";
        watermark($photo_1,$watermarklogo);

        And this is the function i got from there which comes up to my requirement
        Code:
        function watermark($sourcefile, $watermarkfile) {
        		#
        		# $sourcefile = Filename of the picture to be watermarked.
        		# $watermarkfile = Filename of the 24-bit PNG watermark file.
        		#
        		
        		//Get the resource ids of the pictures
        		$watermarkfile_id = imagecreatefrompng($watermarkfile);
        		
        		imagealphablending($watermarkfile_id, false);
        		imageSaveAlpha($watermarkfile_id, true);
        		
        		$fileType = strtolower(substr($sourcefile, strlen($sourcefile)-3));
        		
        		switch($fileType) {
        			case('gif'):
        				$sourcefile_id = imagecreatefromgif($sourcefile);
        				break;
        			case('png'):
        				$sourcefile_id = imagecreatefrompng($sourcefile);
        				break;
        			default:
        				$sourcefile_id = imagecreatefromjpeg($sourcefile);
        		}
        		//Get the sizes of both pix  
        		$sourcefile_width=imagesx($sourcefile_id);
        		$sourcefile_height=imagesy($sourcefile_id);
        		$watermarkfile_width=imagesx($watermarkfile_id);
        		$watermarkfile_height=imagesy($watermarkfile_id);
        	
        		$dest_x = ( $sourcefile_width / 2 ) - ( $watermarkfile_width / 2 );
        		$dest_y = ( $sourcefile_height / 2 ) - ( $watermarkfile_height / 2 );
        	
        		// if a gif, we have to upsample it to a truecolor image
        		if($fileType == 'gif') {
        			// create an empty truecolor container
        			$tempimage = imagecreatetruecolor($sourcefile_width, $sourcefile_height);
        	   		// copy the 8-bit gif into the truecolor image
        			imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0, $sourcefile_width, $sourcefile_height);
        	  		// copy the source_id int
        			$sourcefile_id = $tempimage;
        		}
        		imagecopy($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0, $watermarkfile_width, $watermarkfile_height);
        		//Create a jpeg out of the modified picture
        		switch($fileType) {	
        			// remember we don't need gif any more, so we use only png or jpeg.
        			// See the upsaple code immediately above to see how we handle gifs
        			case('png'):
        				header("Content-type: image/png");
        				imagepng ($sourcefile_id);
        				break;
        			default:
        				header("Content-type: image/jpg");
        				imagejpeg ($sourcefile_id);
        		}
        		imagedestroy($sourcefile_id);
        		imagedestroy($watermarkfile_id);
        	}

        kindly help me out to sort out my problem pleaseeeee

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          any errors, warnings, notices? have you tried with bare/sample images (without uploading) first? did you check the function return values?

          Comment

          • neovantage
            New Member
            • Aug 2008
            • 245

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

            I am attaching the image of it
            Attached Files

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              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

              Comment

              • neovantage
                New Member
                • Aug 2008
                • 245

                #8
                It is saying that cannot modify header information
                Warning: Cannot modify header information - headers already sent by (output started at E:\server\htdoc s\themosaicdesi gns\site\projec ts\carsbay\incl udes\thumbnail. class.php:423) in E:\server\htdoc s\themosaicdesi gns\site\projec ts\carsbay\edit-photos.php on line 272

                Comment

                • Dormilich
                  Recognized Expert Expert
                  • Aug 2008
                  • 8694

                  #9
                  what does
                  output started at E:\server\htdoc s\themosaicdesi gns\site\projec ts\ca rsbay\includes\ thumbnail.class .php:423
                  refer to?

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    Originally posted by neovantage
                    It is saying that cannot modify header information
                    On line 423 of E:\server\htdoc s\themosaicdesi gns\site\projec ts\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.

                    Comment

                    • neovantage
                      New Member
                      • Aug 2008
                      • 245

                      #11
                      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

                      Comment

                      • neovantage
                        New Member
                        • Aug 2008
                        • 245

                        #12
                        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

                        Comment

                        • neovantage
                          New Member
                          • Aug 2008
                          • 245

                          #13
                          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

                          Comment

                          • Dormilich
                            Recognized Expert Expert
                            • Aug 2008
                            • 8694

                            #14
                            first, check what's causing the output in thumbnail.class .php on line 423.

                            Comment

                            • neovantage
                              New Member
                              • Aug 2008
                              • 245

                              #15
                              i am attaching the file thumbnail.class .php file as in line 423 there is nothing in it
                              Attached Files

                              Comment

                              Working...