0

i m having a page in which users upload their images to convert into black and white image..

i tried some of the code from internet but it works only for jpeg image when i upload some gif

or png images it shows an full black image or the same image with the same color scale...

any codes appreciated.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
vijay
  • 65
  • 3
  • 12
  • At least post the code you're using and what you suspect the problem may be. If you're just looking for a copy+paste script you probably won't find it here. – Syntax Error Apr 24 '10 at 07:18
  • 1
    possible duplicate of http://stackoverflow.com/questions/254388/how-do-you-convert-an-image-to-black-and-white-in-php – spoulson Apr 30 '10 at 17:44

2 Answers2

0

i cant tell because you didnt show us the code but it sounds like you need to test for the image type you got from the user before you init the image in GD.

i bet you have a problem with this function

$image = imagecreatefromjpeg($filename);

you need to test for image type and optionally call one of these function

imagecreatefrompng($filename)

imagecreatefromgif($filename)

try this

if ($img = imagecreatefrompng($file))
else if ($img = imagecreatefromjpeg($file))

...


Community
  • 1
  • 1
David Chan
  • 7,347
  • 1
  • 28
  • 49
0

Use the imagecolorallocatealpha() function to allocate color while keeping track of the background color.

Example:

 $color = imagecolorallocatealpha($image, 0, 0, 0,127); // transparent color
Nathan
  • 4,009
  • 2
  • 20
  • 21
Shahid Karimi
  • 4,096
  • 17
  • 62
  • 104