用PHP像素化图像
前几天,我需要隐藏图像,但保持原始图像不变,因此我不想使用明暗滤镜来做复杂的事情,我决定最好的方法是对图像进行像素化。像素化图像所需要做的只是缩小图像,然后将其放大到原始大小,从而降低图像质量。
以下代码将对jpeg图像执行此过程。pixelate量变量用于通过除法减小第一个图像的宽度和高度,然后将它们再次乘回到输出图像的原始值。切记将更ImageCreateFromJPEG()改为所需的格式。
$imgfile = 'mushrooms.jpg';
$image = ImageCreateFromJPEG($imgfile);
$imagex = imagesx($image);
$imagey = imagesy($image);
//像素化量
$pixelate_amount = 10;
# Create version of the original image:
$tmpImage = ImageCreateTrueColor($imagex, $imagey);
imagecopyresized($tmpImage, $image, 0, 0, 0, 0, round($imagex / $pixelate_amount), round($imagey / $pixelate_amount), $imagex, $imagey);
# Create 100% version ... blow it back up to it's initial size:
$pixelated = ImageCreateTrueColor($imagex, $imagey);
imagecopyresized($pixelated, $tmpImage, 0, 0, 0, 0, $imagex, $imagey, round($imagex / $pixelate_amount), round($imagey / $pixelate_amount));
header("Content-Type: image/JPEG");
imageJPEG($pixelated, "", 75);这将采用以下图像:
并将其更改为:
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短