2808 explained code solutions for 75 technologies


php-gdHow to make image grayscale


<?php

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

imagefilter($im, IMG_FILTER_GRAYSCALE);

imagePng($im, '/tmp/image.png');ctrl + c
/var/www/examples/heroine.png

path to image to grayscale

imagecreatefrompng

creates 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