nut*_*les 12 php image crop thumbnails
我正在寻找创建100px×100px维度的缩略图.我已经看过许多文章解释这些方法,但如果要保持尺寸比,大多数文章最终会有宽度!=高度.
例如,我有一个450像素×350像素的图像.我想通过100px裁剪到100px.如果我保持这个比例,我最终会得到100px到77px.当我将这些图像列在行和列中时,这会让它变得难看.然而,没有尺寸比的图像看起来也很糟糕.
我看过flickr的图像,看起来很棒.例如:
缩略图:http://farm1.static.flickr.com/23/32608803_29470dfeeb_s.jpg
中等大小:http://farm1.static.flickr.com/23/32608803_29470dfeeb.jpg
大尺寸:HTTP:// farm1 .static.flickr.com/23/32608803_29470dfeeb_b.jpg
TKS
Sve*_*cke 38
这是通过仅使用图像的一部分作为具有1:1纵横比(主要是图像的中心)的缩略图来完成的.如果仔细观察,可以在flickr缩略图中看到它.
因为你的问题中有"裁剪",我不确定你是否已经知道这一点,但是你想知道什么呢?
要使用裁剪,这是一个例子:
//Your Image
$imgSrc = "image.jpg";
//getting the image dimensions
list($width, $height) = getimagesize($imgSrc);
//saving the image into memory (for manipulation with GD Library)
$myImage = imagecreatefromjpeg($imgSrc);
// calculating the part of the image to use for thumbnail
if ($width > $height) {
$y = 0;
$x = ($width - $height) / 2;
$smallestSide = $height;
} else {
$x = 0;
$y = ($height - $width) / 2;
$smallestSide = $width;
}
// copying the part into thumbnail
$thumbSize = 100;
$thumb = imagecreatetruecolor($thumbSize, $thumbSize);
imagecopyresampled($thumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);
//final output
header('Content-type: image/jpeg');
imagejpeg($thumb);
Run Code Online (Sandbox Code Playgroud)