467,912 Members | 1,693 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,912 developers. It's quick & easy.

hwo to save a new created image on disk

100+
Hey all,
i have created image by mixing logo and the original image. It create image and show in the same window.

I have done 3 steps for this.
First i upload an image to my server by using move_upload_file, then i resize it using class "thumbnail.class.php"

My next step was to embed company logo in it(which i already done) and save new embedded logo image to the path where i first upload the original image i mean i want to overwrite the new created image on the previously uploaded image in my step1.

Here is my code which upload image first, resize it and then create a new embed logo image

Expand|Select|Wrap|Line Numbers
  1. include("includes/thumbnail.class.php");
  2.  
  3. $file_extension=strtolower(get_ext($_FILES['photo_1']['name']));
  4. $photo_1="images/cars/".time().'_1.'.$file_extension;
  5. copy($_FILES['photo_1']['tmp_name'],$photo_1);
  6. $imageproduct = new Thumbnail($photo_1, 640, 480, 100);
  7. $imageproduct->save($photo_1);
  8.  
  9. $watermarklogo="images/logo.png";
  10. $imagelogo = watermark($photo_1,$watermarklogo);
  11.  
Here is my Watermark function code which produce the embedded logo image

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.  
When it produce my embed logo image, it shows me the new produce image on the same window. Please find the attached image for reference


I want to save the new produce image on the path where in first step i upload the image.
i have the path information but how can i overwrite the new produce image on the existing uploaded image.

Kindly help me out to sort out my problem.

Awaiting of reply

kind regards,
Mohsin Rafique
Attached Images
File Type: jpg s-1.jpg (20.2 KB, 122 views)
File Type: jpg s-2.jpg (22.2 KB, 102 views)
File Type: jpg s-3.jpg (22.0 KB, 116 views)
File Type: jpg s-4.jpg (16.5 KB, 114 views)
Jun 15 '09 #1
  • viewed: 2733
Share:
3 Replies
100+
there is a function "imagejpeg" in watermark function which overwrite the uploaded image but it do not work normal. it just give me a url. i am attaching picture of it.

I am giving 8 pictures upload feature at the same time. But my function only work for first image and it stops and show the url as shown in attached image.

I want that it works with every uploaded image and works with normal i mean if i will upload 8 images, it automatically upload all 8 images and refresh the page and also show the uploaded images too on that same page. But when i include that watermark function it stops me to after overwriting very first uploaded image and show the URL. i want that it works with every uploaded image and then show me the uploaded image at the same page.

Awaiting of reply
Attached Images
File Type: jpg s-5.jpg (10.3 KB, 96 views)
Jun 15 '09 #2
100+
I have done that myself.
Hurrayyyyyyyyyyyy

I just need to exclude header from watermark script. It was all i have to do is. Now my script is working fine.
Jun 15 '09 #3
Atli
Expert 4TB
Hi.

Glad you solved the problem!
And thanks for sharing the solution. Might be useful for somebody else facing the same problem.
Jun 15 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Tim T | last post: by
1 post views Thread by garethrichardadams | last post: by
4 posts views Thread by Hrvoje Vrbanc | last post: by
4 posts views Thread by Logician | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.