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
- include("includes/thumbnail.class.php");
- $file_extension=strtolower(get_ext($_FILES['photo_1']['name']));
- $photo_1="images/cars/".time().'_1.'.$file_extension;
- copy($_FILES['photo_1']['tmp_name'],$photo_1);
- $imageproduct = new Thumbnail($photo_1, 640, 480, 100);
- $imageproduct->save($photo_1);
- $watermarklogo="images/logo.png";
- $imagelogo = watermark($photo_1,$watermarklogo);
Expand|Select|Wrap|Line Numbers
- 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);
- }
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