我试图调整图片大小并将其显示在浏览器上。我使用php_image_magician来调整数据库中的图像大小。它成功地调整了图像的大小。我想显示图像而不是saveImage($magicianObj -> saveImage('img.jpeg');
)。如何正确回显此图像echo "<img src='".???."' />";
require_once(PAGEINC.'php_image_magician.php');
$magicianObj = new imageLib("http://localhost".$newsfirstimgpath);
$magicianObj -> resizeImage(50, 50, 'crop');
$magicianObj -> saveImage('img.jpeg');
答案 0 :(得分:0)
您可以使用库的displayImage
功能,如下所示:
$magicianObj->displayImage('jpeg',100); // first param tells display as jpeg and second specifies the quality of the image
您可以在this link检查第2529行查找displayImage
参考
修改强>
在php_image_magician.php
public function getImageSrc($fileType = 'jpg') {
ob_start();
if (!is_resource($this->imageResized)) { if ($this->debug) { die('saveImage: This is not a resource.'); }else{ die(); }}
switch($fileType)
{
case 'jpg':
case 'jpeg':
imagejpeg($this->imageResized, NULL, $imageQuality);
break;
case 'gif':
imagegif($this->imageResized);
break;
case 'png':
// *** Scale quality from 0-100 to 0-9
$scaleQuality = round(($imageQuality/100) * 9);
// *** Invert qualit setting as 0 is best, not 9
$invertScaleQuality = 9 - $scaleQuality;
imagepng($this->imageResized, NULL, $invertScaleQuality);
break;
case 'bmp':
die('bmp file format is not supported.');
break;
default:
// *** No extension - No save.
die('file extension not supported.');
break;
}
$response = ob_get_contents();
ob_end_clean();
return 'data:image/'.$fileType.';base64,' . base64_encode( $response );
}
使用以下代码来回显图像:
echo '<img src="'.$magicianObj->getImageSrc('jpeg').'" />';