I am trying to cut an image for small pieces from database. My code here:
$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);
But in the line $offset_x, the (int)(round($height*360/$width)) is not working. If I put an intval, like 100, all the images will cut well, but the offset position is not willing. So how to true string to int?
BTW: In this case, I will call and cut image from database in a foreach, should I unset something after this code in the foreach?
$height,$widthfrommysql query => $row['width'] and $row['height'].