PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 11, 2022

[FIXED] how to change background color image using php gd

 October 11, 2022     gd, php     No comments   

Issue

I have created a website http://www.example.com and i want to change color of its widget using PHP GD.

lets widget URL is www.example.com/widget.gif

When I pass hexadecimal value to this URL it should change colour like

www.example.com/widget.gif?bg=#CC66CC

Solution

Try the following code

Give your color code in gd function IMG_FILTER_COLORIZE

    $imgname = "source.png";           
    $im = imagecreatefrompng ($imgname);              
    if($im && imagefilter($im, IMG_FILTER_COLORIZE, 137, 113, 79))               
    {
         echo 'Image successfully shaded green.';                

         imagepng($im, 'result.png');             
         imagedestroy($im);                     
    }                  
   else               
   {
        echo 'Green shading failed.';
   }


Answered By - Hardik Raval
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing