First some information about using PHP, GD and imagecopy. You must have access to PHP scripting and GD on your server. You can check with your Administrator if you are not sure.
The following set of PHP codes will be used in every file. They are required. They speak to the server telling it what you want to do.
For this first lesson this is the image I am going to put together with php imagecopy. Here are the five images I will be using. You can upload those or choose alternatives:
Here are some images to choose from: Angles Reversed Angles | |||
White angles Grad-Pals |
Upload your choice of images to your directory where your php script will be. The next set of codes tells the server what images to use and what their variable names are. You can name them whatever you want. Be sure to use a dollar sign preceding the name. Also be sure to use a semicolon at the end of every line of code. The line "imagecreatefromjpeg()" is a php command and must be used for each image. The URL of your image is placed in the parenthesis with single quotes (can use double but single is a good habit as in more complicated PHP scripts you have nested quotes with single quotes inside a line with double quotes around it).
$G140 = imagecreatefromjpeg ('G140.jpg');
$Gn140 = imagecreatefromjpeg ('Gn140.jpg');
$B140 = imagecreatefromjpeg ('B140.jpg');
$Bn140 = imagecreatefromjpeg ('Bn140.jpg');
$mod = imagecreatefromjpeg('gradMod2.jpg');
These images too will also need to be destroyed when you are finished with them, at the end of the script, under this line of code just repeat the code for each image:
imagedestroy($im);
imagedestroy($G140);
imagedestroy($Gn140);
imagedestroy($B140);
imagedestroy($Bn140);
imagedestroy($mod);
Now come the imagecopy codes which is what builds the actual image. Basically what you need to use for parameters are:
(destination, source, X, Y of back, X, Y of top, W, H of top)
In other words, the X, Y of where on the background you would like to place your image, the X, Y of the part of the image that you are placing on top along with the W, H of the top image. Briefly this chart shows the X, Y of a 50x50 image as 0, 0, the beginning pixel (top left) and 50, 50, is the W, H (bottom right).
0,0 | ||||||
50,50 |
Here are the codes I used for my image:
imagecopy($im, $mod, 135, 60, 0, 0, 50, 189);
imagecopy($im, $Bn140, 110, 250, 0, 0, 50, 50);
imagecopy($im, $B140, 160, 250, 0, 0, 50, 50);
imagecopy($im, $G140, 110, 300, 0, 0, 50, 50);
imagecopy($im, $Gn140, 160, 300, 0, 0, 50, 50);
Looking at the first line:
imagecopy() is a PHP command. $im is the background, $mod is the girl image, 135 is the distance from the left on the background where I want to place the image, 60 is the distance from the top on the background, 0, 0, is the top left corner of the girl image and 50, 189 is the W, H of the girl image. As far as trying to decide where on the page to put the image it is sometimes easiest to decide where the center is and work around that to ensure that you have enough space to the left and right of the page as you keep adding more images. Then trim the extra space off at IM when you are through. If you know exactly how large your final image will be you can figure out the number for that and make the width and height of your background so that there will be nothing to trim off your final image. I have done this image both ways and simple math should tell you what the numbers are.
Here are the Codes for the final image, all put together. Here are the Codes again for the same image with no background to trim off.
You can CCP the codes, but understanding them is the key to future success. I don't expect you to memorize them right off. I still have to go back in to old scripts to CCP.
Now your php script is ready to be made into a jpg. There are three ways to do this.
That was a lot of information for a short tute but there was a lot to cover. The following lessons should be shorter and easier, once you've got the basics. The second lesson will look at gif and png manipulations using this first php script.