php resize image on upload

Solutions on MaxInterview for php resize image on upload by the best coders in the world

showing results for - "php resize image on upload"
Heston
04 Oct 2017
1// resize on upload
2$maxDim = 800;
3$file_name = $_FILES['myFile']['tmp_name'];
4list($width, $height, $type, $attr) = getimagesize( $file_name );
5if ( $width > $maxDim || $height > $maxDim ) {
6    $target_filename = $file_name;
7    $ratio = $width/$height;
8    if( $ratio > 1) {
9        $new_width = $maxDim;
10        $new_height = $maxDim/$ratio;
11    } else {
12        $new_width = $maxDim*$ratio;
13        $new_height = $maxDim;
14    }
15    $src = imagecreatefromstring( file_get_contents( $file_name ) );
16    $dst = imagecreatetruecolor( $new_width, $new_height );
17    imagecopyresampled( $dst, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
18    imagedestroy( $src );
19    imagepng( $dst, $target_filename ); // adjust format as needed
20    imagedestroy( $dst );
21}
Marco
04 Jul 2016
1$maxDim = 800;
2$file_name = $_FILES['myFile']['tmp_name'];
3list($width, $height, $type, $attr) = getimagesize( $file_name );
4if ( $width > $maxDim || $height > $maxDim ) {
5    $target_filename = $file_name;
6    $ratio = $width/$height;
7    if( $ratio > 1) {
8        $new_width = $maxDim;
9        $new_height = $maxDim/$ratio;
10    } else {
11        $new_width = $maxDim*$ratio;
12        $new_height = $maxDim;
13    }
14    $src = imagecreatefromstring( file_get_contents( $file_name ) );
15    $dst = imagecreatetruecolor( $new_width, $new_height );
16    imagecopyresampled( $dst, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
17    imagedestroy( $src );
18    imagepng( $dst, $target_filename ); // adjust format as needed
19    imagedestroy( $dst );
20}
queries leading to this page
image resizer in phpphp image resize and upload nulledresize image php with contentresize image resolution with code phpphp resize image after uploadphp resize image by scalephp resize imgsresize image using php interventationresizing image using php before uploadingimage resize in php scripthow i can resize the image in phpresize image php classhow to resize an image in phpimage resize library phphow to increase image upload size in phpresize image in php pngresize php imageimage resizer php classimage resize php scriptimageresize phpnew image resize phpresize image in php persentimgae resize function for php functionphp image resize libraryresize image when upload phpphp resize image to file sizehow to resize uploaded image in phpphp images resize andresize image upload phpimageresize in phpphp resize image on uploadphp create image resizeresize image before upload in phpresize images before uploading in phpusing img resize phpresize image from external url phpphp resize image libraryimage resize php functionhow to resize image in php before uploadresizing image with phpphp resize image while get imagestore resize image phphowto resize images with phpimage resize in php examplephp image resizeimage resize in phpphp correct way to resize uploaded imageimage save to local afiter resize phpphp upload resize imageresize images at upload phpphp image downsizerphp reduce image resolutionphp resize image for webimagesize phpphp image change resolutionwhy file upload change photo size phpupload image with resize in phpphp fastest way to resize imghow to resize image in php and downloadhow to resize an image with phpresize image php libraryphp upload resize image code 24image resize phpimage resize function for php functionhow to upload and resize image in php 3fresising image in phpimg resize phpscale down image phpresize image using php resize image php scriptchange img size in phpresizing an image in a database phpresize image in phpphp imageresizephp resize image and echophp send resized imageresizing image in phpimage resize php examplephp resize image before displayphp resize imphp fileupload resize imagephp resize imageresizeimage phpresize image from user in phphow to resize image with php php change image size on uploadhow to resize an image in php on uploadhow to set upload image size in phpimage resize phpphp on upload resize and compress imagephp image resize function resize image php before uploadphp resize image before uploadresize upload image phpinline style resize image phpimage upload with resize in phpjpg resize phpphp resize image before upload exampleresize image phphow to resize image before upload in phpresize image file with phpimage resizer phpphp upload image dimensionsresize jpg php coderesize image php functionresize image phpphp image file resizepackage image resize in phphow to shrink size of image after upload in phpimage upload file size phphow can control image resolution upload in phpphp scale imagehow to resize images with phpphp upload and resize imagephp copy image and resizehow to resize image in phpchange image dimension phpphp script to get and resize imagehow image reszie in phpresize image before upload phpphp image resize and uploadupload image resize php mysqlimage resize library for phpphp photo resizefile upload resize image phpresize image with phpupload image with resize phpmake image resizer phpphp resize image on upload