CORRECTION
Replace
echo 'img src="data:image/jpeg:base64,'.base64_encode($image).'">';
With
echo '<img src="data:image/jpeg:base64,'.base64_encode($image).'">';
PHP - Manual: Gmagick::scaleimage
2024-12-22
(PECL gmagick >= Unknown)
Gmagick::scaleimage — Scales the size of an image
Scales the size of an image to the given dimensions. The other parameter will be calculated if 0 is passed as either param.
width
The number of columns in the scaled image.
height
The number of rows in the scaled image.
The Gmagick object.
错误时抛出 GmagickException。
CORRECTION
Replace
echo 'img src="data:image/jpeg:base64,'.base64_encode($image).'">';
With
echo '<img src="data:image/jpeg:base64,'.base64_encode($image).'">';
Simple method to load an image from file, resize and display without writing to disk.
tested on jpg, gif and bmp
<?php
$image= new Gmagick( "yourimage.jpg");
$image->scaleimage(300,0);
echo 'img src="data:image/jpeg:base64,'.base64_encode($image).'">';
$image->destroy();
?>