Solved

create an image and save it in a directory using php

Posted on 2008-06-18
2
1,417 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now