I wanna convert an colored image to grayscale, i am using the below mentioned code.
<?php
header ('Content-type: image/jpeg');

// Load the target image
$rDestImg = imagecreatefromjpeg('test.jpg');

// Create a blank source image
$rSourceImg = ImageCreate (0,0);

// Merge the source with the destination
ImageCopyMergeGray ($rDestImg, $rSourceImg, 0, 0, 0, 0, imageSX($rDestImg), imageSY($rDestImg), 0);

// Print the image to the browser
Imagejpeg($rDestImg);
?>

But i get an error on the imagecreate line saying invalid width or my whole php crashes 😕. I am on a win2k machine, IIS, php 4.3.0 with GD 2.0.

Kindly Help!!

    // Create a blank source image
    $rSourceImg = ImageCreate (0,0);

    width: 0
    height: 0

    try a bigger image.

      i tried putting

      $rSourceImg = ImageCreate (10,10);

      or other values, but i still dont get the image

        yea, the code looks a bit strange to me.

        think you should try to ImageCopyMergeGray() the $sourceImage you created to the destImage. right know you are doing this the other way around.

        i changed the 'merge-factor' to 30 and this works in some way grayscaled. if possible use ImageCreateTrueColor(), else use ImageCreate(), depending on your gd-version.

        $src = ImageCreateFromJpeg("salon.jpg");
        $srcDim = getImageSize("salon.jpg");
        
        $dest = ImageCreate($srcDim[0], $srcDim[1]);  // make empty image
        ImageColorAllocate($dest, 255, 255, 255);  // white background
        
        // copy $src to $dest
        ImageCopyMergeGray($dest, $src, 0, 0, 0, 0, $srcDim[0], $srcDim[1], 30);
        
        ImageJpeg($dest);
        
          Write a Reply...