简体   繁体   English

将Image JPG转换为GIF并将其打印到BASE64中的标签IMG中

[英]Convert Image JPG to GIF and print it into the tag IMG in BASE64

This is my actual code, I have troubles related with the right visualization of the gif image generated on the fly for my php script. 这是我的实际代码,我遇到了与为我的PHP脚本动态生成的gif图像正确可视化相关的麻烦。 If I access directly to the gif image generated by the script the browser show it good but if I try from my current script through tag img, the browser couldn't show it. 如果我直接访问脚本生成的gif图像,浏览器将显示良好,但如果我通过img标签从当前脚本中尝试,浏览器将无法显示它。

Any suggest friends ? 有什么建议的朋友吗?

<?php
$src = imagecreatefromjpeg( 'img/ejemplo-2.jpg' );
list( $width, $height ) = getimagesize( 'img/ejemplo-2.jpg' );
$tmp = imagecreatetruecolor( '300', '300');
imagecopyresampled( $tmp, $src, 0, 0, 0, 0, '300', '300', $width, $height );
$imagen = imagegif( $tmp, "filename.gif" );
$data   = "data:image/gif;base64," . base64_encode( file_get_contents( "filename.gif" ) );
?>

<img src="<?php echo $data; ?>" width="300" height="300" />

While Opera 7.2+, Firefox, Safari, Netscape, and Mozilla support data URIs, Internet Explorer 5-7 do not. Opera 7.2 +,Firefox,Safari,Netscape和Mozilla支持数据URI,而Internet Explorer 5-7不支持。 However, Internet Explorer 8 reportedly does, by passing the Acid2 test, making data URLs a viable alternative for embedding smaller decorative images. 但是,据报道,Internet Explorer 8通过了Acid2测试,使数据URL成为嵌入较小装饰性图像的可行选择。 There are workarounds that you can use for older versions of Internet Explorer. 有一些解决方法可用于旧版本的Internet Explorer。

If you want to get round browser cache issues, append a random generated number onto the end of the img src : 如果要解决浏览器缓存问题,请将随机生成的数字附加到img src的末尾:

<img src="test.jpg?12345" />

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

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