473,881 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hwo to save a new created image on disk

245 New Member
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_fil e, then i resize it using class "thumbnail.clas s.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, 134 views)
File Type: jpg s-2.jpg (22.2 KB, 117 views)
File Type: jpg s-3.jpg (22.0 KB, 138 views)
File Type: jpg s-4.jpg (16.5 KB, 135 views)
Jun 15 '09 #1
3 3109
245 New Member
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, 110 views)
Jun 15 '09 #2
245 New Member
I have done that myself.
Hurrayyyyyyyyyy yy

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 Recognized Expert Expert

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 they will not be aware of optimising graphics for the web, if someone uploads a 300k 640x480 jpeg for example, i need to be able to shrink it down to a - say 400x300 65k file BEFORE saving to my webserver. I have been looking on the web and have...
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 bigger on disk? I have noticed that saving to GIF doesn't have this problem. I have tried adjusting the encoder properties with not much success. I also notice that taking JPEG to tiff results in large files to. What gives?
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 using BackgroundImageLayout = ImageLayout.Tiled. It all works - I get a tiled image.
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 page and thus to save a copy of a picure at let's say http://www.blabla.com/pic.jpg to predefined location on my hard disk. Thanks in advance, Hrvoje
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 the transparency is working properly because if I save the created image to the local hard disk and then view it in a web page or an image editor, the transparency is correct. I can also view the transparency on-the-fly in a Windows.Forms...
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 it in the size: 16x16, and I hope someone could help me out a bit? Code that saves from bmp to ico (32x32): private void cmdConvert_Click(object sender, EventArgs e) { string source = @"d:\image.bmp";
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") myGraphics = PictureBox1.CreateGraphics Dim expansionRectangle As New Rectangle(25, 550, 1000, 350) Dim destRectangle1 As New Rectangle(0, 0, 1000, 350) myGraphics.DrawImage(myBitmap, destRectangle1, expansionRectangle,
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 copy error. My Internet connected PC is not the development machine, so I cannot debug on that PC and my other PC has no Internet connection. So I cannot debug using .NET as normal.
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, I need to save the image first to disk. How do I do that? Here's a preview of what I'm trying to do, at the end of the page you'll see an image, that image is what i'm trying to insert in an email when a user clicks the button. ...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.