Image Manipulation with PHP and the GD Library


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //to black and white
  2. if(!file_exists('dw-bw.png')) {
  3. $img = imagecreatefrompng('dw-manipulate-me.png');
  4. imagefilter($img,IMG_FILTER_GRAYSCALE);
  5. imagepng($img,'db-bw.png');
  6. imagedestroy($img);
  7. }
  8.  
  9. //to negative
  10. if(!file_exists('dw-negative.png')) {
  11. $img = imagecreatefrompng('dw-manipulate-me.png');
  12. imagefilter($img,IMG_FILTER_NEGATE);
  13. imagepng($img,'db-negative.png');
  14. imagedestroy($img);
  15. }
  16.  
  17.  
  18. //to Sepia
  19. if(!file_exists('dw-sepia.png')) {
  20. $img = imagecreatefrompng('dw-manipulate-me.png');
  21. imagefilter($img,IMG_FILTER_GRAYSCALE);
  22. imagefilter($img,IMG_FILTER_COLORIZE,100,50,0);
  23. imagepng($img,'db-sepia.png');
  24. imagedestroy($img);
  25. }

URL: http://davidwalsh.name/php-image-filter

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.