PHP itself allows various interception, regeneration, merging, compression and other operations to images, so in order to pursue perfection, you can refer to the following.
Shortly after I started using DEDE, I found that the automatically generated thumbnail pictures were actually reduced by the original image based on the customized maximum length and width and the original proportion, which was not conducive to the layout of the image index page. I had to use automatic judgment to adjust the height and width in CSS - but it was more resource-consuming. So I decided to change the thumbnail function - thanks again for the open source of DEDE! !
Modify file: inc_photograph.php
Program code
if($toWH<=$srcWH){
$ftoW=$toW;
$ftoH=$ftoW*($srcH/$srcW);
}
else{
$ftoH=$toH;
$ftoW=$ftoH*($srcW/$srcH);
}
Change to
Program code
$ftoH=$toH;
$ftoW=$toW;
if ($toWH<=$srcWH) {
$src_Y = 0;
$src_X = ($srcW-$srcH*$toWH)/2;
$srcW = $srcH*$toWH;
} else {
$src_X = 0;
$src_Y = ($srcH-$srcW/$toWH)/2;
$srcH = $srcW/$toWH;
}
Key points:
Program code
($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH)
Change to
Program code
($ni,$im,0,0,$src_X,$src_Y,$ftoW,$ftoH,$srcW,$srcH)
In fact, just a small change is to capture a part of the column in the original image that meets the length and width ratio of the custom thumbnail in the length and width ratio.
Shortly after I started using DEDE, I found that the automatically generated thumbnail pictures were actually reduced by the original image based on the customized maximum length and width and the original proportion, which was not conducive to the layout of the image index page. I had to use automatic judgment to adjust the height and width in CSS - but it was more resource-consuming. So I decided to change the thumbnail function - thanks again for the open source of DEDE! !
Modify file: inc_photograph.php
Program code
if($toWH<=$srcWH){
$ftoW=$toW;
$ftoH=$ftoW*($srcH/$srcW);
}
else{
$ftoH=$toH;
$ftoW=$ftoH*($srcW/$srcH);
}
Change to
Program code
$ftoH=$toH;
$ftoW=$toW;
if ($toWH<=$srcWH) {
$src_Y = 0;
$src_X = ($srcW-$srcH*$toWH)/2;
$srcW = $srcH*$toWH;
} else {
$src_X = 0;
$src_Y = ($srcH-$srcW/$toWH)/2;
$srcH = $srcW/$toWH;
}
Key points:
Program code
($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH)
Change to
Program code
($ni,$im,0,0,$src_X,$src_Y,$ftoW,$ftoH,$srcW,$srcH)
In fact, just a small change is to capture a part of the column in the original image that meets the length and width ratio of the custom thumbnail in the length and width ratio.