简体   繁体   中英

GD imagefilter no image output

I'm trying to convert an jpg image to grayscale with GD imagefilter but i can't get the filtered image to output on the browser. I use this code

<?php 
$thumb="w=250&q=100";
$imgstring = get_image('cover_image',1,1,0,NULL,$thumb);
$im = imagecreatefromjpeg($imgstring);
imagefilter($im, IMG_FILTER_GRAYSCALE);
header("Content-type: image/jpg");
imagejpeg($im);
imagedestroy($im);
?>

**The $imgstring is the url string of the image (' http://xxx.xx/image.jpg ').

With the header content line the result is an error "Warning: Cannot modify header information - headers already sent by..." followed by what appears to be the image code (a lot of question marks characters and other garbage).

Without the header content line the result is just the image code(?) again (symbols and characters)

What's wrong?

The error is exactly what it says - something in your code has caused output to be performed, which kills the header() call, preventing the content-type from being set. In the absence of any valid content-type header, the client browser assumes text/plain, and is showing your JPEG image - as raw "garbage".

You need to figure out WHERE in your code that output is being performed (I'm willing to bet a shiny penny it's in that get_image() function, and eliminate it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM