You are invited to Log in or Register a free Frihost Account!

PHP including images inside images

As part of my new site, users will get images to share accross the internet. These images are created dynamically and get the information/statics from my database.

One of these is a review field, and rather than have x/5 Stars as text, I'd rather have it as an image - inside the other image.

I've had a quick look through Google, and the PHP manual, but can't seem to find anything - Does anyone know the function, or if it even exists?
Well Do you know how to make images? If you do then you should be able to impliment imagecopymerge to copy a star onto your pics.

Once you have that mastered all you need to do it make and if statement.


$feedback = (info from db);
if (($feedback => 0.5) && ($feedback < 1.5)){

code for copy merging the one star image...

else if if (($feedback => 1.5) && ($feedback < 2.5)){

code for copy merging the two star image


I am sure you get the point now. Good luck and another thing... It might look better to have a star image like youtube has where it has the 3 stars filled in and then two blank stars. I don't know though. I'm sure you will be able to do the making stars bit yourself.
Thanks for that, here's what I've ended up doing:

 $rateImage = ImageCreateFromPng("../images/ratings/". $row['rating']. ".png");
 imagecopymerge($myImage, $rateImage, 20, 105, 0, 0, 85, 16, 100);

But my rating image has alpha transparency - do you know how I can enable it, at the moment the image has a black border around it.

- Garion
Fire Boar
imagesavealpha($rateImage, true);

Just add that line after your ImageCreateFromPng line.
Fire Boar wrote:
imagesavealpha($rateImage, true);

Just add that line after your ImageCreateFromPng line.

Thanks for the quick response, but that doesn't seem to want to work for me - Could it have something to do with ImageCreateFromPng?
I haven't actually used this but try this instead:

imagecopymerge($myImage, $rateImage, 20, 105, 0, 0, 85, 16, 0);

or try this:

imagealphablending($rateImage, 1);

imagecopy($myImage, $rateImage, 20, 105, 0, 0, 85, 16);

Hope something works.
Nothing, sorry

I'm thinking now it could have something to do with the image itself. It shows as transparent in FireFox, but I might need to increase/decrease the alpha channel.
Fire Boar
If it's working in Firefox, your script is definitely fine. It's the web browser that is the problem. Go to this page:

There are probably some types of PNG format that handle transparancy properly on most last-gen - to - current-gen browsers. I know that Internet Explorer 5 and possibly 6 have trouble with some PNG files.
your best bet is to stick with using ImageCreatFromGIF instead of png, gif has transparency options across all browsers i believe, and IE doesnt support pngs. I had the same problem before, but now i just use gifs for transparent overlaying images.
Fire Boar
GIF vs PNG... there are pros and cons to each. PNGs are better, smaller, more modern and generally becoming more standard. Unfortunately, there are still quite a few people using Internet Explorer 5 or below. PNG transparancy is only supported in IE 6 or above (and all of the proper browsers such as Firefox).

GIFs, on the other hand, are slightly bulkier, but are more compatible, because they have been around for longer.

It's your choice, I suppose.
Related topics
Google in your scripts
[tutor] How to protect images without htaccess using PHP
Dynamic PHP Images
PHP Tutorials
Service Temporarily Unavailable (Down again?)
PHP - checking lengths
[php] including from lib folder impossible
pls suggest software to generate thumbnails etc...
include() for phpbb = blank?
Best Method for layout
PHP GD Images Default 75 dpi change to 300dpi??
PHP and images
POST a form in the Same page
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

© 2005-2011 Frihost, forums powered by phpBB.