누군가가 PHP로 작성된 이미지 크기 조정 기능을 지원하지만 PHPThumb과 같은 방식으로 이미지의 크기를 조정해야하는지 궁금합니다. 따라서 새 이미지의 너비와 높이를 설정하면이 함수는 업로드 된 이미지 (그리고 mantain 종횡비)를 새 너비와 높이에 맞춰야합니다.PHP에서 이미지 크기를 조정하는 현명한 방법
도움을 주시면 감사하겠습니다.
감사합니다.
누군가가 PHP로 작성된 이미지 크기 조정 기능을 지원하지만 PHPThumb과 같은 방식으로 이미지의 크기를 조정해야하는지 궁금합니다. 따라서 새 이미지의 너비와 높이를 설정하면이 함수는 업로드 된 이미지 (그리고 mantain 종횡비)를 새 너비와 높이에 맞춰야합니다.PHP에서 이미지 크기를 조정하는 현명한 방법
도움을 주시면 감사하겠습니다.
감사합니다.
GD 또는 ImageMagick을 사용합니다. 두 가지 모두 훌륭한 라이브러리가 있습니다.
http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php, 난 나 자신을 연습 this image class을 wroted.
GD를 사용하면 확실히 향상시킬 수 있으며, 도움이 되길 바랍니다.
편집 : 아무런 통제력이없는 문제에 대해 2 번 downvotes 이후, 나는 파스 티에 수업을 씁니다. The Example
기억
클래스는 잘 작동하지만, 기본 OOP를 배우기 위해 연습했다. 원본 이미지의 가로 세로 비율을 계산 : 나는이, 당신이 게으른 사용자 확인이되기를 바랍니다
크리스마스에)
우리는 더 나은 사람
크기 조정 후 작물 접근 방식은 대상 이미지 (폭 또는 높이)보다 더 커지는 중간 이미지를 만들기 위해 제약 조건으로 사용합니다. 최종적으로 중간 이미지를 대상 차원으로 자릅니다.
seam carving! 당신이 당신의 서버에 설치되는 ImageMagick에 의존하는 경우도 "liquid rescale" in ImageMagick라고
를 (또한 there 참조), 그것은 GD보다 더 많은 기능을 제공합니다. 나의 이해에서
은 영업 이익의 문제는 새로운 차원을 계산보다는
@Psyche 크기 조정에 대한 자세한이며, 이것은 실제로 간단한 연산 문제입니다. 640x480 이미지가 있고이를 200x200 "상자"에 표시하려고한다고 가정합니다.
$sw = 640; $sh = 480;
$dw = 200; $dh = 200;
는 상자의 가로 세로 비율을 찾아 원래의와 비교하고이 당신에게 200x150을주는 새로운 이미지
$sr = $sw/$sh;
$dr = $dw/$dh;
if($sr > $dr)
$dh = round($dw/$sr);
else
$dw = round($dh * $sr);
에 대한 하나의 높이의 폭을 계산하고이되는 크기입니다
나는 이것을 몇 년 전에 작성 했으므로 정확히 찾고있는 것을 수행한다. 이것은 너비와 높이를 계산하는 것 뿐이므로 Imagick을 직접 호출하여 이러한 계산을 실제로 적용해야합니다.
/**
* ImageIntelligentResize()
*
* @global Intelligently resizes images using a providid max width and height
* @param mixed $imagePath
* @param mixed $maxWidth
* @param mixed $maxHeight
* @param mixed $alwaysUpscale
* @return
*/
function ImageIntelligentResize($imagePath, $maxWidth, $maxHeight, $alwaysUpscale)
{
// garbage in, garbage out
if (IsNullOrEmpty($imagePath) || !is_file($imagePath) || IsNullOrEmpty($maxWidth) || IsNullOrEmpty($maxHeight))
{
return array("width"=>"", "height"=>"");
}
// if our thumbnail size is too big, adjust it via HTML
$size = getimagesize($imagePath);
$origWidth = $size[0];
$origHeight = $size[1];
// Check if the image we're grabbing is larger than the max width or height or if we always want it resized
if ($alwaysUpscale || $origWidth > $maxWidth || $origHeight > $maxHeight)
{
// it is so let's resize the image intelligently
// check if our image is landscape or portrait
if ($origWidth > $origHeight)
{
// target image is landscape/wide (ex: 4x3)
$newWidth = $maxWidth;
$ratio = $maxWidth/$origWidth;
$newHeight = floor($origHeight * $ratio);
// make sure the image wasn't heigher than expected
if ($newHeight > $maxHeight)
{
// it is so limit by the height
$newHeight = $maxHeight;
$ratio = $maxHeight/$origHeight;
$newWidth = floor($origWidth * $ratio);
}
}
else
{
// target image is portrait/tall (ex: 3x4)
$newHeight = $maxHeight;
$ratio = $maxHeight/$origHeight;
$newWidth = floor($origWidth * $ratio);
// make sure the image wasn't wider than expected
if ($newWidth > $maxWidth)
{
// it is so limit by the width
$newWidth = $maxWidth;
$ratio = $maxWidth/$origWidth;
$newHeight = floor($origHeight * $ratio);
}
}
}
// it's not, so just use the current height and width
else
{
$newWidth = $origWidth;
$newHeight = $origHeight;
}
return array("width"=>$newWidth, "height"=>$newHeight);
}
글쎄, 검색은 분명히 도움이 될 것입니다. '관련'참조 –