问题
<?php
$f = new SaeFetchurl();
$img_data = $f->fetch( 'http://ss7.sinaimg.cn/bmiddle/488efcbbt7b5c4ae51ca6&690' );
$img = new SaeImage();
$img->setData( $img_data );
$img->resize(200);
$img->flipH();
$img->flipV();
$new_data = $img->exec();
$img->exec( 'jpg' , true );
if ($new_data === false)
var_dump($img->errno(), $img->errmsg());
?>
Here is the code from sina sae. It offers images service. When I paste the code on my page, I just can see the mess in the browser.
What does this "$img->exec( 'jpg' , true );" mean?
How to output the images using php?
回答1:
With mess you mean a bunch of characters?
Try to set the header information
header('Content-type: image/jpeg');
回答2:
The mess might be the interpreted image (code). You might want to include the php script into the src
attribute of an html image tag.
Like:
<img src="foobar.php?optional=params" />
回答3:
just adding on to Alex. I been using this over the past new days and I've noticed that my images will not be shown on the page without the extra 2 lines below.
header('Content-type: image/jpeg');
imagepng($img);
imagedestroy($img);
来源:https://stackoverflow.com/questions/7889119/how-to-output-images-using-php