<?php ???$url = ‘1.jpg‘; ???$base64_img = base64_encode(file_get_contents($url));//将图片转base64编码 ???$imgArr = getimagesize($url);//取得图片的大小,类型等 ???$img_url = "data:{$imgArr[‘mime‘]};base64,{$base64_img}";//合成图片的base64编码成 ???echo ‘<img src="‘.$img_url.‘" />‘; ???exit(); ???????//生成转化过来的图片 ???$imgBase64 = "";//base64格式的图片 ???if ( preg_match(‘/^(data:\s*image\/(\w+);base64,)/‘, $imgBase64, $result) ){ ???????$imgBase64 = urlencode( str_replace($result[1], ‘‘, $imgBase64) ); ???} ???$filePath = "data/".time().".jpg"; ???file_put_contents($filePath, base64_decode(urldecode($imgBase64)));?>
php 图片转base4的格式
原文地址:https://www.cnblogs.com/thatme/p/10200576.html