内嵌产生超过长度的图像 [英] Inline generated images exceeding length

查看:164
本文介绍了内嵌产生超过长度的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP来生成图像,并能正常工作。我有麻烦却显示这些图像:

I am using PHP to generate images and this works fine. I am having trouble displaying these images however:

我的图像生成器是需要吨的参数和数据的负载生成图像的PHP文件。由于过量的具有要传递给发电机,使用GET容器为我不工作,所以数据被通过POST请求发送。这种请求的结果是原始图像数据

My image generator is a PHP file that takes tons of parameters and loads of data to generate the image. Because of the excessive amounts that has to be passed to the generator, using the GET container does not work for me, so the data is sent via a POST request. The result of this request is the raw image data.

我使用

$result = post_request('http://myurl.com/graphx/generator.php', $data);
if($result['status'] == 'ok') {
    echo "<img src=\"data:image/png;base64,".
        base64_encode($result['content'])."\"/>\n";
}

显示我的形象。这适用于非常小的图像,但他们得到更大(300像素* 300像素为例),则不再显示的图像(这似乎是某处削减)。

to display my image. This works for very small images, but as they get bigger (300px*300px for example), the image is not displayed anymore (it seems to be cut somewhere).

是我的做法是否合理?

是否有大小问题的任何解决方法吗?

更新:

当我让生成图像保存到一个文件中,创建的文件包含图像,我希望它是。另外,如果我发电机转换成一个GET发电机,下面code正常工作,以及:

When I let the generator save the image to a file, the created file contains the image as I want it to be. Also, if convert my generator into a GET-generator, the following code works properly as well:

$data = http_build_query($data);
echo "<img src=\"http://myurl.com/graphx/get_generator.php?{$data}\"/>\n";

所以它肯定似乎是无论是POST请求,或转化成的base64 格式的问题。我使用的是POST请求,如下所示

So it definitely seems to be a problem with either the POST request, or the conversion into the base64 format. I'm using the POST request as shown here.

推荐答案

我建议让您的网页的结构是这样的:

I'd suggest having your page be structured like this:

主页:

<img src="imageproxy.php" />

imageproxy.php:

imageproxy.php:

<?php
$result = post_request('http://myurl.com/graphx/generator.php', $data);
header('Content-type: image/png');
if($result['status'] == 'ok') {
    echo $result['content']);
} else {
    readfile('error_message_image.png');
}

而不是试图用数据URI和长度限制工作,只是有你的代理脚本输出的实际原始图像数据,并把它作为你的客户端HTML的图像。

instead of trying to work with data uris and length limits, just have your proxy script output the actual raw image data and treat it as an image in your client-side html.

这篇关于内嵌产生超过长度的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆