用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);这将采用以下图像:
并将其更改为:
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下