简体   繁体   English

在php中解码base64图像后转换图像64X64 px

[英]convert image 64X64 px after decoding base64 image in php

hi i am retriving a base64 encoded version of image and i have to stored it by cropping it to small size. 嗨,我正在恢复base64编码版本的图像,我必须通过裁剪到小尺寸来存储它。 now i am not able to crop the image please help me my Code is as follow.. Please help me in cropping base 64 image 现在我无法裁剪图像请帮助我我的代码如下..请帮我在裁剪基地64图像

    $data = str_replace('data:image/png;base64,', '', $note['file']);
                $data = str_replace(' ', '+', $data);
                $decodedFile = base64_decode($data);
$file = fopen($destination , 'wb');


if(!fwrite($file, $decodedFile)){
                //return("ERROR: can't save file to $destination");
                return '-1';
            }
                fclose($file);

You can use the gd library for create the image file from binary code: 您可以使用gd库从二进制代码创建映像文件:

function binaryToFile($binary_imagen, $width, $height, $new_name, $url_destiny) {

    try{
        //actual size
        $info    = getimagesizefromstring($binary_imagen);
        $old_width = $info[0];
        $old_height = $info[1];

        //new resource
        $resource = imagecreatefromstring($binary_imagen);

        $resource_copy  = imagecreatetruecolor($width, $height);

        imagealphablending( $resource_copy , false );
        imagesavealpha( $resource_copy , true );

        imagecopyresampled($resource_copy, $resource, 0, 0, 0, 0,
                   $width, $height, 
                   $old_width, $old_height);

        $url = $url_destiny."/".$new_name".png";
        $final = imagepng($resource_copy, $url, 9);

        imagedestroy($resource);
        imagedestroy($resource_copy);

        return 1;

    }catch (Exception $e) {
        return 0;
    }

}

Not sure what your need but if it is some what like this you want to achieve then may be this will help you 不确定你需要什么,但如果它是你希望实现的那样,那么这可能会对你有所帮助

PHP crop image from base64_decode PHP从base64_decode裁剪图像

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

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