【发布时间】:2016-05-28 07:39:43
【问题描述】:
我制作了两个 GIF 来解释我想要做什么。灰色边框是我追求的尺寸(700 * 525)。他们在这个问题的底部。
我希望所有大于给定宽度和高度的图像都缩小到边界(从中心),然后裁剪掉边缘。这是我整理的一些代码来尝试这样做:
if ($heightofimage => 700 && $widthofimage => 525){
if ($heightofimage > $widthofimage){
$widthofimage = 525;
$heightofimage = //scaled height.
//crop height to 700.
}
if ($heightofimage < $widthofimage){
$widthofimage = //scaled width.
$heightofimage = 700;
//crop width to 525.
}
}else{
echo "image too small";
}
这里有一些 GIF 可以直观地解释我想要实现的目标:
GIF 1:这里的图片比例在x方向上太多了
GIF 2:这里的图片比例在y方向上太大了
@timclutton 的图像质量比较
所以我使用了PHP (click here to do your own test with the php)的方法,然后将其与原始照片进行比较,您可以看到有很大的不同!:
你的PHP 方法:
(来源:tragicclothing.co.uk)
实际文件:
(来源:mujjo.com)
【问题讨论】:
-
您可能对 CSS
background-size:cover感兴趣。 Example here。请注意有些有限的browser compatibility。 (顺便说一下,动画 GIF 的使用很好。) -
请提供一个有效的jsfiddle.net 来说明您目前所掌握的情况。
-
我喜欢你的 GIF!很好的解释自己的方式,XD!