PHP generated image as an overlay?
Posted: Wed Feb 28, 2007 3:35 am
I have hit a bit of a snag. I have 2 PHP files, portion.php and template.php. Template uses a default image as a template and uses Portion to overlay an image onto it.
Portion works fine, when you go to the page it will create the image I need, everything okay there.
When I go to Template uses the imagecreatefrompng() function to create a PNG image from the Portion class, this is where the snag is.
The problem comes when I try and make the overlay image PHP generated. If I reference it to a standard PNG file, it works perfectly. I am guessing that the Portion class isn't making a true PNG image for the imagecreatefrompng() function.
Here are the two files I am using:
If I change the line
to
it works fine, so here is my question to you PHP guru's, is there another header I need in the portion.php file???
Thanks
Portion works fine, when you go to the page it will create the image I need, everything okay there.
When I go to Template uses the imagecreatefrompng() function to create a PNG image from the Portion class, this is where the snag is.
The problem comes when I try and make the overlay image PHP generated. If I reference it to a standard PNG file, it works perfectly. I am guessing that the Portion class isn't making a true PNG image for the imagecreatefrompng() function.
Here are the two files I am using:
Code: Select all
<?php
// Header mime type
header('Content-type: image/png');
// Only get a small part of the image
$image = imagecreatefromgif('overlay.gif');
$crop = imagecreatetruecolor(75, 20);
// Make the small part of the image smaller
imagecopy($crop, $image, 0, 0, 40, 13, 75, 20);
imagecopyresampled($crop, $crop, 0, 0, 0, 0, 55, 20, imagesx($crop), imagesy($crop));
// Only get what we need from the new smaller image
$crop2 = imagecreatetruecolor(55, 20);
imagecopy($crop2, $crop, 0, 0, 0, 0, 55, 20);
// Create the PNG graphic
imagepng($crop2);Code: Select all
<?php
// Header mime type
header('Content-type: image/png');
// The overlay image
$overlay = 'portion.php';
$overlay = imagecreatefrompng($overlay);
$overlayX = imagesx($overlay);
$overlayY = imagesy($overlay);
// The template image
$template = imagecreatefromgif('template.gif');
$templateX = imagesx($template);
$templateY = imagesy($template);
// The dimentions of the final graphic
$imageX = 90;
$imageY = 50;
// Where to place the overlay
$offsetX = 30;
$offsetY = 12;
// Create the basic graphic holder
$image = imagecreatetruecolor($imageX, $imageY);
// Put the template in the image
imagecopyresampled($image, $template, 0, 0, 0, 0, $imageX, $imageY, $templateX, $templateY);
// Overlay the overlay graphic onto the template
imagecopymerge($image, $overlay, $offsetX, $offsetY, 0, 0, $overlayX, $overlayY, 99);
// Create the PNG graphic
imagepng($image);Code: Select all
$overlay = 'portion.php';Code: Select all
$overlay = 'portion.png';Thanks