簡體   English   中英

在php中解碼base64圖像后轉換圖像64X64 px

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

嗨,我正在恢復base64編碼版本的圖像,我必須通過裁剪到小尺寸來存儲它。 現在我無法裁剪圖像請幫助我我的代碼如下..請幫我在裁剪基地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);

您可以使用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;
    }

}

不確定你需要什么,但如果它是你希望實現的那樣,那么這可能會對你有所幫助

PHP從base64_decode裁剪圖像

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM