简体   繁体   English

为什么此图像不起作用?

[英]Why doesn't this image work?

I wrote: 我写:

$im = imagecreatefromstring($im_string);        
return imagegif($im,'a.gif');

The content of variable $im_string I get from a ZIP file. 我从一个ZIP文件中获取的变量$im_string的内容。 It should work, but it returns '1' . 它应该工作,但是返回'1'

Why is the reason? 原因何在?

According to the php manual imagegif returns as follows: 根据php手册, imagegif返回如下:

Return Values 返回值

Returns TRUE on success or FALSE on failure. 成功返回TRUE,失败返回FALSE。

What did you expect it to return? 您期望它返回什么? The image data? 图像数据?

Edit: To answer the question in the comment. 编辑:要回答评论中的问题。 To output the actual data you should either not have the second argument (which sends it to the file a.gif) so that it sends the data straight to the output or you pick up that a.gif and sends the data in there. 要输出实际数据,您应该没有第二个参数(将其发送到文件a.gif),以便它直接将数据发送到输出,或者您选择该a.gif并将数据发送到那里。 In both cases you need to remember to send a correct content-type header back to the client as well. 在这两种情况下,您都需要记住将正确的内容类型标头发送回客户端。

The imagegif function returns a boolean, so a return value of 1 would indicate that it was successful. imagegif函数返回一个布尔值,因此返回值1表示已成功。

If you need to return the actual image data, you need pass the second parameter as well and read the data from the file, or buffer the output of the function. 如果需要返回实际的图像数据,则还需要传递第二个参数,并从文件中读取数据,或缓冲函数的输出。

<?php
ob_start();
$im = imagecreatefromstring($im_string);        
imagegif($im);
$img_data = ob_get_clean();

return $img_data;
?>

Or: 要么:

<?php
$im = imagecreatefromstring($im_string);        
imagegif($im, 'a.gif');

$img_data = file_get_contents('a.gif');

return $img_data;
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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