1

I am trying to filter/render image to grayscale. But I'm having trouble on saving the output file on directory. Please see my code below:

$img_source = '/path/test.jpg';
$img = imagecreatefromjpeg($img_source);

$img_height = imagesy($img);
$img_width = imagesx($img);

$target_path = '/path/test_grayscale.jpg';

// some code for grayscale process

imagejpeg($img, $target_path);
Eddie
  • 26,593
  • 6
  • 36
  • 58

1 Answers1

1

From PHP.net:

<?php
$im = imagecreatefrompng('dave.png');

if($im && imagefilter($im, IMG_FILTER_GRAYSCALE))
{
    echo 'Image converted to grayscale.';

    imagepng($im, 'dave.png');
}
else
{
    echo 'Conversion to grayscale failed.';
}

imagedestroy($im);
?>

If it isn't the grayscale process that's causing you trouble, you ought to share relevant information about your problem.

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778