How to output images using php?

痞子三分冷 提交于 2021-01-29 03:50:46

问题


<?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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!