Skip to content

Latest commit

 

History

History
33 lines (22 loc) · 802 Bytes

how-to-make-image-grayscale.md

File metadata and controls

33 lines (22 loc) · 802 Bytes

How to make image grayscale

<?php

$file = '/var/www/examples/heroine.png';
$im = imagecreatefrompng($file);

imagefilter($im, IMG_FILTER_GRAYSCALE);

imagePng($im, '/tmp/image.png');
  • /var/www/examples/heroine.png - path to image to grayscale
  • imagecreatefrompng - creates lib:GD image object from given PNG image
  • imagefilter - applies filter to image
  • IMG_FILTER_GRAYSCALE - converts colors for our image to grayscale
  • imagePng - saves image in PNG format to the given path

group: filter

Example:

<?php

$file = '/var/www/examples/heroine.png';
$im = imagecreatefrompng($file);

imagefilter($im, IMG_FILTER_GRAYSCALE);

imagepng($im, '/tmp/image.png');