raduenea Posted August 19, 2013 Share Posted August 19, 2013 I have a code that make a re-size and crop to a picture. First he resize the picture and after that put the picture in the middle of the white background. The only problem is if a picture is vertical add black color in the right side instead of white. For horizontal pictures it's ok. Why is adding the black color in the right side ? Thank you Link to comment https://forums.phpfreaks.com/topic/281359-image-resizecrop/ Share on other sites More sharing options...
raduenea Posted August 19, 2013 Author Share Posted August 19, 2013 I forgot to add the code: function resize_image($max_width,$max_height){ $width = $this->getWidth($this->image_location); $height = $this->getHeight($this->image_location); $new_width = ""; $new_height = ""; $with_scale = $width/$max_width; $height_scale = $height/$max_height; if($with_scale > $height_scale){ $new_width = $max_width; $new_height = ($max_width/$width) * $height; }else{ $new_height = $max_height; $new_width = ($max_height/$height) * $width; } $x_mid = $new_width / 2; $y_mid = $new_height / 2; $newImage = imagecreatetruecolor($new_width,$new_height); $source = imagecreatefromjpeg($this->image_location); imagecopyresampled($newImage,$source,0,0,0,0,$new_width,$new_height,$width,$height); $final = imagecreatetruecolor($max_width, $max_height); imagecopyresampled($final, $newImage, 0, 0, ($x_mid - ($max_width / 2)), ($y_mid - ($max_height / 2)), $max_width, $max_height, $max_width, $max_height); $bg_color = imagecolorallocate ($final, 255, 255, 255); imagefill($final, 0, 0, $bg_color); imagejpeg($final,$this->new_location,80); chmod($this->new_location, 0777); return $this->new_location; } Link to comment https://forums.phpfreaks.com/topic/281359-image-resizecrop/#findComment-1445872 Share on other sites More sharing options...
raduenea Posted August 20, 2013 Author Share Posted August 20, 2013 Anyone ? Link to comment https://forums.phpfreaks.com/topic/281359-image-resizecrop/#findComment-1446012 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.