如何获得图像大小从基地64字符串在PHP中 [英] How to get image size from base 64 string in php

查看:282
本文介绍了如何获得图像大小从基地64字符串在PHP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的基础64的字符串图像我必须移动文件夹中,并将图像路径存储在数据库中,但我必须限制文件大小。如何可以这样做:

我从64字符串生成图像的代码如下所示:

  / ** if image is attached with请求** / 
$图片=MyBase64StringHere;
list($ type,$ Image)= explode(';',$ Image);
list(,$ Image)= explode(',',$ Image);

/ **解码base 64映像** /
$ Image = base64_decode($ Image);

我试图得到图像大小,如:
$ size = getimagesize($ Image);

但是从这里获取文件的宽度和高度。有人告诉我如何从文件大小this.Thanks

解决方案

请检查这个:
$ b $解码后,试试这个: getimagesizefromstring(),如果你使用 PHP 5.4 ,如果使用 PHP 5.3 ,那么你可以用下面的方法检查。

 <?php 
如果(!function_exists('getimagesizefromstring')){
函数getimagesizefromstring($ data)
{
$ uri ='data:// application / octet-stream; base64,'。 BASE64_ENCODE($数据);
返回getimagesize($ uri);
}
}


I am getting the base 64 for string for image I have to move in folder and store the image path in database but I have to limit the file size.How can I do this:

My code for generate image from base 64 string is like:

/** if image is attached with request **/
 $Image = "MyBase64StringHere";
 list($type, $Image) = explode(';', $Image);
 list(, $Image)      = explode(',', $Image);

/** decode the base 64 image **/
 $Image = base64_decode($Image);

I have tried to get image size like:
$size =  getimagesize($Image);

But from this am getting file width and height.Can someone tell me how can I get file size from this.Thanks

解决方案

Please check this :

After decoding, try with this : getimagesizefromstring(), if you are with PHP 5.4, if using PHP 5.3, then you can check with the following method.

<?php
if (!function_exists('getimagesizefromstring')) {
    function getimagesizefromstring($data)
    {
        $uri = 'data://application/octet-stream;base64,' . base64_encode($data);
        return getimagesize($uri);
    }
}

这篇关于如何获得图像大小从基地64字符串在PHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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