mstation Posted September 28, 2009 Share Posted September 28, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/175818-solved-images-and-tricks-need-help/ Share on other sites More sharing options...
Alex Posted September 28, 2009 Share Posted September 28, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/175818-solved-images-and-tricks-need-help/#findComment-926463 Share on other sites More sharing options...
Alex Posted September 28, 2009 Share Posted September 28, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/175818-solved-images-and-tricks-need-help/#findComment-926470 Share on other sites More sharing options...
mstation Posted September 28, 2009 Author Share Posted September 28, 2009 thanks a lot! the example worked perfectly! Quote Link to comment https://forums.phpfreaks.com/topic/175818-solved-images-and-tricks-need-help/#findComment-926536 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.