472,962 Members | 2,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,962 software developers and data experts.

hwo to save a new created image on disk

245 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");
  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);
  9. $watermarklogo="images/logo.png";
  10. $imagelogo = watermark($photo_1,$watermarklogo);
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.         #
  7.         //Get the resource ids of the pictures
  8.         $watermarkfile_id = imagecreatefrompng($watermarkfile);
  10.         imagealphablending($watermarkfile_id, false);
  11.         imageSaveAlpha($watermarkfile_id, true);
  13.         $fileType = strtolower(substr($sourcefile, strlen($sourcefile)-3));
  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);
  31.         $dest_x = ( $sourcefile_width / 2 ) - ( $watermarkfile_width / 2 );
  32.         $dest_y = ( $sourcefile_height / 2 ) - ( $watermarkfile_height / 2 );
  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.     }
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, 130 views)
File Type: jpg s-2.jpg (22.2 KB, 111 views)
File Type: jpg s-3.jpg (22.0 KB, 122 views)
File Type: jpg s-4.jpg (16.5 KB, 124 views)
Jun 15 '09 #1
3 3049
245 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, 104 views)
Jun 15 '09 #2
245 100+
I have done that myself.

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
5,058 Expert 4TB

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

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

Similar topics

by: Tim T | last post by:
Hi, Could someone please point to to a tutorial / code for dynamically resizing images on upload, THEN saving to disk on the webserver. I need users to be able to upload images to my server, but...
by: Ben Becker | last post by:
Why when I open an image in VB.NET, display it in an image box, then call the image.save property to save it to a file as a different format (e.g. tiff image with save to jpeg) does it become 10...
by: garethrichardadams | last post by:
Hello all, I've got a user control I've created called canvas. Doesn't do much at the moment. I've set the background image to a small bitmap using BackgroundImage and I've set it to tiled...
by: Hrvoje Vrbanc | last post by:
I would like to know the most efficient way to copy an image from an Internet URL to the local hard disk by means of using an ASP.NET page. So, I would like to click the button on the ASP.NET...
by: Dale | last post by:
I am creating GIF images with transparent backgrounds on-the-fly for a web app and rendering them by using System.Drawing.Image.Save(Response.OutputStream, ImageType.GIF). I am confident that...
by: SveinErik | last post by:
Hi, I'm trying to find a method to save bmp, jpg and png files as ico files, 16x16 size. I have managed to convert and save bmp files to icon, but only in 32x32 size. I can't figure out how to save...
by: Joe | last post by:
does anyone know why this source code throws an error?? Dim myBitmap As System.Drawing.Bitmap Dim myGraphics As Graphics myBitmap = New System.Drawing.Bitmap(fileName:="C:\test.tif")...
by: Logician | last post by:
I am running on my PC Windows Forms to collect data from websites, including images. I hit a problem with images and javascript, and I would appreciate any help. The current code fails with a...
by: admiralato | last post by:
Hi guys, I need to insert an image to an email. The IMAGE.SRC of the image is from a file named, Graphics.aspx. What I'm thinking is in order for me to include the generated image in the email,...
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.