我想拍摄本地图像,调整大小并输出 dataURI。为什么我的 base64_encode 代码不起作用?
<?php
// Create an image instance
$imagearray = array('pop3', 'aboutme', 'passions', 'lindahlstudios', 'blog');
foreach ($imagearray as $key) {
echo $key;
//load image
$im = imagecreatefrompng($key.'button4.png');
//set width of resize
$width = 70;
$ratio = $width / imagesx($im);
$height = imagesy($im) * $ratio;
echo ' resizeTo-'.$width.'x'.$height.'<br>';
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $im, 0, 0, 0, 0, $width, $height, imagesx($im), imagesy($im));
//save image to file
//imagepng($new_image, $key.'button4_'.$width.'.png');
//print DataURI
echo base64_encode($new_image);
imagedestroy($new_image);
}
?>