PHP 7 Script to Convert RGB Image to Grayscale (Black and White) Image in Browser Full Project For Beginners

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments

 

Welcome folks today in this blog post we will be converting RGB image to grayscale (black and white) image in browser using php 7. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started you need to make an index.php file and copy paste the following code

See also  PHP 7 Script to Take Selfie or Picture From Webcamera Using Javascript and Upload Image to Server and MySQL Database Automatically Full Project For Beginners

 

 

index.php

 

 

 

<?php
$imgcreate = imagecreatefrompng('forest.png');

if($imgcreate && imagefilter($imgcreate, IMG_FILTER_GRAYSCALE))
{
    echo 'Grayscale image generated.';

    imagepng($imgcreate, 'forest_gray.png');
}
else
{
    echo 'Grayscale conversion of image failed.';
}

imagedestroy($imgcreate);
?>

Leave a Reply