There is any php script that resize image proportionally with max widht or height??
Ex: I upload image and this original size is w:500 h:1000. But, I want to resize this thats max height is width and height is 500... That the script resize the image for w: 250 h: 500
If the Shift key is held down whilst moving the handle, then the proportions of the object will be preserved. For example, if I hold Shift and drag the bottom edge upwards to reduce the size by half, then the right edge will automatically move to the left to reduce the width of the object by the same amount.
The imagescale() function is an inbuilt function in PHP which is used to scale an image using the given new width and height. Parameters: This function accepts four parameters as mentioned above and described below: $image: It is returned by one of the image creation functions, such as imagecreatetruecolor().
Manually setting the object to a specific proportion:Right-click the object. On the shortcut menu, click Format<object type>. In the dialog box, click the Size tab. Under Scale, enter the percentage of the original height or width you want the object resized to.
All you need is the aspect ratio. Something along these lines:
$fn = $_FILES['image']['tmp_name']; $size = getimagesize($fn); $ratio = $size[0]/$size[1]; // width/height if( $ratio > 1) { $width = 500; $height = 500/$ratio; } else { $width = 500*$ratio; $height = 500; } $src = imagecreatefromstring(file_get_contents($fn)); $dst = imagecreatetruecolor($width,$height); imagecopyresampled($dst,$src,0,0,0,0,$width,$height,$size[0],$size[1]); imagedestroy($src); imagepng($dst,$target_filename_here); // adjust format as needed imagedestroy($dst);
You'll need to add some error checking, but this should get you started.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With