- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用axios通过ajax发送base64字符串。使用下面的方法,当它从 Base64 数据编码回 jpg 时,我会以某种方式丢失大量数据。我怎样才能在不丢失数据的情况下发送此信息?
我从输入中抓取文件并将其发送到
var reader = new FileReader();
reader.readAsDataURL(file);
base64 字符串作为 ajax 发送,axios 为
axios.post('url', {main: img})
PHP 脚本接收帖子如下:
$incoming = json_decode(file_get_contents('php://input'))->main;
$mainImage = str_replace('data:image/jpeg;base64,', '', $incoming);
$img = imagecreatefromstring(base64_decode($mainImage));
$imageSave = imagejpeg($img, './uploaded.jpg');
例如,最近保存在服务器上的文件只有14k,但我上传到输入字段的原始文件是19k。我将客户端上传的 base64 输出到预览 div,并且该图像保存为 19k jpg,所以我假设它是 php 脚本。关于导致数据丢失的原因有什么想法吗?也许有一些axios config value ?
最佳答案
发生的情况是,前端正在发送 base64 编码的二进制图像数据。
当前,您正在解码图像、创建新图像并将其另存为 jpg。这只会再次压缩图像。
如果您只是解码数据并将其保存到文件(扩展名为 .jpg),您将获得上传图像的精确副本。
incoming = json_decode(file_get_contents('php://input'))->main;
$mainImage = str_replace('data:image/jpeg;base64,', '', $incoming);
file_put_contents('./uploaded.jpg', base64_decode($mainImage));
关于javascript - Base64 图像到 imagecreatefromstring() 丢失数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42385529/
尝试在 wordpress 管理界面中上传时,我收到主题中提到的错误。 我的服务器使用 php-fpm 运行 nginx,PHP 版本是 5.3.0。 我在谷歌上搜索了很多关于这个问题的信息,但我找不
我在 PHP 中调整图像大小时遇到问题;似乎从我使用 imagecreatefromstring 或 imagecreatefrompng 加载图像的那一刻起,颜色就会改变并褪色。 我知道我必须使
这段代码有什么问题? 我收到这些错误: 警告:imagecreatefromstring():gd-png:致命的 libpng 错误:读取错误:第 5 行 D:\wamp\www\img\inde
最好的使用方法是什么imagecreatefromstring()或 .bmp 的替代方法文件? 这样: $data = file_get_contents($path); $image = imag
我一直在努力让我的应用程序变得透明(它在存储图像之前动态调整图像大小),我认为在对 imagealphablending 和 imagesavealpha。源图像从未以适当的透明度加载! // Wit
通常我使用 imagecreatefromjpeg() 然后使用 getimagesize(),但是对于 Firefox 3 我需要绕过这个不同。所以现在我正在使用 imagecreatefromst
假设我的代码看起来像这样: "; // // more stuff here // ?> 我要替换什么/* 这里是什么? */这样我的图像数据就会显示出来? 谢谢。 最佳答案 What do I re
这是我的代码: $data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl' . 'BMVEUAAAD///+l2Z/dAAA
我正在使用 imagecreatefromstring,目前正在验证正确的图像文件格式。 所以一个链接: swqkdwfibqwfwf 不会工作,因为它不是有效的文件类型。但我刚刚发现了这一点: si
我正在使用 imagecreatefromstring,目前正在验证正确的图像文件格式。 所以一个链接: swqkdwfibqwfwf 不会工作,因为它不是有效的文件类型。但我刚刚发现了这一点: si
我正在使用axios通过ajax发送base64字符串。使用下面的方法,当它从 Base64 数据编码回 jpg 时,我会以某种方式丢失大量数据。我怎样才能在不丢失数据的情况下发送此信息? 我从输入中
以下是我获取图片的方式: $coverurl = 'https://api.someurl/api/v1/img/' . $somenumber . '/l'; //$iheaders contai
我在 Javascript 和 PHP 之间以字符串形式发送图像时遇到问题。到目前为止,我有: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAA
我有一个简单的服务,它使用通过 URL 传递的参数生成任何文本的 PNG 图像。参数之一是文本本身,其余参数是“字体”、“颜色”、“字体粗细”等。 这种 URL 的一个例子是: http://pics
有没有办法使用 imagecreatefromstring() 并以某种方式获取图像类型? 最佳答案 当您使用 imagecreatefrom... 方法时,图像将作为未压缩的位图加载到内存中。此时并
我正在尝试从我无法控制的外部站点加载图像。 大多数时候它工作正常(到目前为止测试了数百张图像)。 它现在给我一个特定图像的错误: imagecreatefromstring():gd-jpeg、lib
目前,如果用户将照片发布/上传到我的 PHP 脚本,我会从这样的代码开始 getimagesize($_FILES['picture1']['tmp_name']); 然后我对它做了更多的事情,但我也
我创建了一个脚本,其中我必须在运行时使用 64 位编码的字符串创建图像。我使用 PHP 的 imagecreatefromstring 函数,但它在我的基于 Windows XAMPP 的 PHP 中
以下 JavaScript 代码会将 SVG 字符串转换为图像 blob,然后可用于在浏览器中显示: var data = '' + '' + '' +
当我尝试在不正确的 png 图像上使用 php-gd 函数时,出现致命的 PHP 错误。这似乎是某种错误,因为根据函数文档(例如 imagecreatefrompng): * @return reso
我是一名优秀的程序员,十分优秀!