사각형 이미지를 PHP의 사각형 모양의 아바타로 어떻게 변경합니까? 업로드 된 이미지의 해상도가 무엇이든 관계없이 중앙 42x42 픽셀 아바타로 크기를 조정할 수 있습니다. 이것은 내가 사용하고있는 PHP 코드입니다. 누구든지 조언 할 수 있습니다.PHP - 사각형 이미지를 사각형 이미지로 변환하려면 어떻게해야합니까?
<?php
//Name you want to save your file as
$save = 'myfile1.jpg';
$file = 'original1.jpg';
echo "Creating file: $save";
$size = 0.45;
header('Content-type: image/jpeg') ;
list($width, $height) = getimagesize($file) ;
$modwidth = $width * $size;
$modheight = $height * $size;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
// Here we are saving the .jpg, you can make this gif or png if you want
//the file name is set above, and the quality is set to 100%
imagejpeg($tn, $save, 100) ;
?>
을 사용하면 이미지의 가로 세로 비율을 제한 하시겠습니까?를 – Dai
원 반경 체인저 사용 – Smash
@Dai OP는 최대 크기 제곱을 얻기 위해 직사각형의 중앙 사각형을 잘라내어 (가장 유용한 픽셀 데이터를 얻으려고합니다.) 42x42로 다시 크기 조정하려고합니다. 나는 대답을 쓰면서 10 분을 낭비했다. ... – Shomz