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}
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}