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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.