When importing an image for use, often times the size does not fit your drawing. But with imagecopyresize we can resize it and composite it on our canvas with no need to upload the image or resize it by having to leave the script. But, if you're importing an image what size is it? Well here's how to find out.
print_r ( getImageSize ('URL' ) );
Once you have the original size of the image, you're ready to resize it and apply it to your canvas.
Call Image and ReSize
To begin, we call the image just asif we are going to composite. The following creates the image and gets the height and width.
$logo = ImageCreateFrompng('purple_hat.png');
$logoW = ImageSX($logo);
$logoH = ImageSY($logo);
Now we need to resize it. To do that you subtract the number of pixels from the width and the height. So the newW is the original width minus 28 pixels; and the newH is the original width minus 28 pixels.
Now we create the image at the new width and height.
$image_resized = imagecreate($newW, $newH);
By resampling the image you get a good clean copy. That is done using the original image and the new image.
imagecopyresampled($image_resized, $logo, 0, 0, 0, 0, $newW, $newH, $logoW, $logoH);
Now you composite as usual replacing logo with image_resized; and the new width and height.
ImageCopy($im, $image_resized, 120, 50, 0, 0, $newW, $newH);
You can do this multiple times on your canvas; but you need to give each one different variable names. Once you composite or blend the image it becomes part of your drawing and you may draw on it, tile it, recolor it as you wish.
This zip file contains the original php script and two images and a text script to produce what you see on this page. Let your imagination go and have some fun...!!!