首页 >社区问答列表 >如何在php中,将原有图片进行压缩大小后,在base64编码输出?

如何在php中,将原有图片进行压缩大小后,在base64编码输出?

跨域请求的图片,需要在php中,如下操作base64编码后,img的src引用编码就可以完成类似getImageData的操作

<?php 
$pic = 'a.jpg'; 
$arr = getimagesize($pic); 
$pic = "data:{$arr['mime']};base64," . base64_encode(file_get_contents($pic)); 
?>

问题是图片分辨率2k,加载很慢,现在就想请教大神们,php怎么可以先压缩图片大小在进行编码,输出使用?