Jump to content

[SOLVED] Images and tricks.. need help


mstation

Recommended Posts

Hello all..

 

i am trying to add some images to my website.. the images paths and names are stored into a myslq database where i can set a value to indicated if the image is active or not..

 

i would like to have a color output image for an active link and a grayscale image for a not active link but at the same time have only 1 color image stored on the ftp.. is this possible in someway?

Link to comment
https://forums.phpfreaks.com/topic/175818-solved-images-and-tricks-need-help/
Share on other sites

Yes, it's possible.

 

Using PHP GD.First you'll need to create a new image resource using imagecreatetruecolor(). Then fill it with some gray color using imagefill(). Finally you'll merge your original image resource with the second using imagecopymerge() (utilizing the last parameter of that function to change the alpha transparency).

 

If you need an example just ask.

I made an example, but I can't edit my previous post.. Anyway here it is:

 

<?php
header('Content-type: image/gif');
$original = imagecreatefromgif('http://www.google.com/intl/en_ALL/images/logo.gif'); //Create an image resource of your original image
$gray = imagecreatetruecolor(imagesx($original), imagesy($original)); // Same size as original image
imagefill($gray, 0, 0, imagecolorallocate($gray, 100, 100, 100)); // Fill the new image resource with gray
imagecopymerge($original, $gray, 0, 0, 0, 0, imagesx($original), imagesy($original), 80); //Merge them together
imagegif($original);
?>

 

If you test that example out it'll output a grayed out version of the Google logo.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.