Solved

create an image and save it in a directory using php

Posted on 2008-06-18
2
1,425 Views
Last Modified: 2012-06-27
I created a file tstimg.php using following php script ( please see code snippet) . the code produces a final image and I want to save this final image as a new image in a directory.
copy() function kind of thing does not work.
// File name tstimg.php
// code starts now 
<?php
session_start();
$filename="blank.jpg";
$filename2="1.jpg";
$filename3="2.jpg";
$img_src=imagecreatefromjpeg($filename);
$img_src2=imagecreatefromjpeg($filename2);
$img_src3=imagecreatefromjpeg($filename3);
 
imagecopy($img_src, $img_src2, 15, 17, 0, 0, 200, 65);
imagecopy($img_src, $img_src3, 15, 82, 0, 0, 200, 150);
// how to save final image on server and how to upload 1.jpg ,2.jpg from PC to server
header ("Content-type: image/jpeg");
 
imagejpeg($img_src);
imagedestroy($img_src);
imagedestroy($img_src2);
imagedestroy($img_src3);
?>
// code ends

Open in new window

blank.jpg
1.jpg
2.jpg
0
Comment
Question by:amitbravo
2 Comments
 
LVL 15

Accepted Solution

by:
ncoo earned 500 total points
ID: 21815252


Change the line to:

imagejpeg($img_src,'location/to/save/file.jpg');

See below:
// File name tstimg.php
// code starts now 
<?php
session_start();
$filename="blank.jpg";
$filename2="1.jpg";
$filename3="2.jpg";
$img_src=imagecreatefromjpeg($filename);
$img_src2=imagecreatefromjpeg($filename2);
$img_src3=imagecreatefromjpeg($filename3);
 
imagecopy($img_src, $img_src2, 15, 17, 0, 0, 200, 65);
imagecopy($img_src, $img_src3, 15, 82, 0, 0, 200, 150);
// how to save final image on server and how to upload 1.jpg ,2.jpg from PC to server
//header ("Content-type: image/jpeg");
 
imagejpeg($img_src,'location/to/save/file.jpg');
imagedestroy($img_src);
imagedestroy($img_src2);
imagedestroy($img_src3);
?>
// code ends

Open in new window

0
 
LVL 82

Expert Comment

by:hielo
ID: 21815262
provide a path to imagejpeg($img_src);

imagejpeg($img_src,"C:\images\image.jpg");

http://us3.php.net/manual/en/function.imagejpeg.php
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JQuery Search Filter 2 71
Integrating blogs between to separate WordPress websites 4 33
Survey branching tutorial 11 44
Set a time limit on Wordpress Cookie function. 3 16
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question