473,382 Members | 1,657 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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");
  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, 133 views)
File Type: jpg s-2.jpg (22.2 KB, 114 views)
File Type: jpg s-3.jpg (22.0 KB, 135 views)
File Type: jpg s-4.jpg (16.5 KB, 130 views)
Jun 15 '09 #1
3 3081
neovantage
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, 107 views)
Jun 15 '09 #2
neovantage
245 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
5,058 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

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

Similar topics

2
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...
1
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...
1
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...
4
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...
4
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...
3
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...
13
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")...
4
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...
0
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,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.