데이터베이스에서 작은 조각에 대한 이미지를 자르려고합니다. 여기에 내 코드 : PHP 문자열이 작동하지 않습니다.
$image = imagecreatefromjpeg($filename);
$width = $row['width'];
$height = $row['height'];
$new_width = 480;
$new_height = 360;
$offset_x = (int)(round($height*360/$width));//100
$offset_y = 0;
$new_image = imagecreatetruecolor($new_width, $new_height);
imagecopy($new_image, $image, 0, 0, $offset_x, $offset_y, $width, $height);
imagejpeg($new_image,$newimg);
그러나 라인 $offset_x
에서
(int)(round($height*360/$width))
가 작동하지 않습니다. 을 넣으면
100
과 같이 모두
images
이 잘릴 지 모르지만 오프셋 위치는 기꺼이하지 않습니다. 그래서
true string to int
하는 방법?
BTW :이 경우에는 foreach
의 데이터베이스에서 이미지를 호출하고 자릅니다.이 코드를 foreach에 넣으면 unset
해야합니까?
$ 행은 어디에 설정되어 있습니까? $ height와 $ width의 값은 무엇입니까? – ben
어쩌면 try intval $ offset_x = intval (round ($ height * 360/$ width)); http://php.net/manual/en/function.intval.php – rogerlsmith
@ben,'mysql query => $ row [ 'width']의'$ height','$ width'와 $ row [ 'width' 높이 ']'. –