ImageMagick and the Imagick PHP extension is installed on my host now. Now all generated images keep EXIF/IPTC info (original, medium and thumbnail image, all of them are with EXIF/IPTC data).
I allow visitors to upload hi-res images on site, and in most cases visitors do not optimize/compress images before upload and sometimes image file size is quite big.
For example 12MP image can be 10 MB, but after 85% jpeg compression its file size can be 2-3 times smaller, almost without noticeable loss of quality.
I put this function to functions.php (my theme folder) to compress original image during upload, to save up disk space and speed up loading of hi-res image on page with it.
I allow visitors to upload hi-res images on site, and in most cases visitors do not optimize/compress images before upload and sometimes image file size is quite big.
For example 12MP image can be 10 MB, but after 85% jpeg compression its file size can be 2-3 times smaller, almost without noticeable loss of quality.
I put this function to functions.php (my theme folder) to compress original image during upload, to save up disk space and speed up loading of hi-res image on page with it.
Code:
// Image compression on upload, compress original image function wt_handle_upload_callback( $data ) { $image_quality = 50; // 50% compression $file_path = $data['file']; $image = false; switch ( $data['type'] ) { case 'image/jpeg': { $image = imagecreatefromjpeg( $file_path ); imagejpeg( $image, $file_path, $image_quality ); break; } case 'image/png': { $image = imagecreatefrompng( $file_path ); imagepng( $image, $file_path, $image_quality ); break; } case 'image/gif': { // Nothing to do break; } } return $data; } add_filter( 'wp_handle_upload', 'wt_handle_upload_callback' ); add_filter ('image_strip_meta', false);

Comment