我正在设计一个商店,将产品的图像设置为 div 背景,当您悬停它时,它会从中间变大,等等。我的所有功能都很好,但图像太大了并造成大量滞后。
我已经尝试了几个选项,比如使用 PHP 使图像更小且质量略低,但我无法弄清楚如何将它从 php 中的 jpeg 图像转换为 CSS 将用作背景的格式,因为我不只是将它作为图像打印在页面上,还需要 CSS 动画等来处理它。
background:url(
<?php
if(!$i['Image']){
}else{
$im = $i['Image'];
$image = "../Images/ShopIMG" . $im . ".jpeg";
}
$source_image = imagecreatefromjpeg($image);
$source_imagex = imagesx($source_image);
$source_imagey = imagesy($source_image);
$dest_imagex = 300;
$dest_imagey = 200;
$dest_image = imagecreatetruecolor($dest_imagex, $dest_imagey);
imagecopyresampled($dest_image, $source_image, 0, 0, 0, 0, $dest_imagex,
$dest_imagey, $source_imagex, $source_imagey);
$imageData = imagejpeg($dest_image,NULL,80);
$src = 'data: '.mime_content_type($dest_image).';base64,'.$imageData;
echo($image);
?>) no-repeat center center;
background-size: 115%;
我希望使用较小尺寸和质量的新 php 图像作为背景图像,这样它就不会在页面上占用太多内存并减慢速度,但它会打印出一堆看似 splinter 的随机字符.
最佳答案
拆分图像并上传较低质量的图像首先解决了我的问题。谢谢达曼。
关于php - 降低 php 中图像的大小和质量并用作 CSS 背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54170925/