After testing I realized that Word Press after image upload will make medium and thumbnail sized images of original image without EXIF/IPTC info
I realized it is because GD image library is used on my host, and that is how GD library works by default, strip out all image info.
After research I found out that if ImageMagick and the Imagick PHP extension is used instead of GD library EXIF info will be retained (with ImageMagick default settings) in generated resized image files.
UPDATE 1
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.
// Image compression on upload, compress original image
function wt_handle_upload_callback( $data ) {
$image_quality = 85; // 85% 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' );
It works fine, original image is compressed, BUT this function removes EXIF/IPTC data on all images (I need to keep EXIT, at least on original image). Without function above, original and all resized images are with EXIF/IPTC data (because ImageMagick is installed), but original image is not compresed than.
How to fix, adjust function above to keep EXIF?
UPDATE 2
WP 4.5 is reseased with some image hadling improvements, and also with option to preserve image EXIF data (in case ImageMagic is used on host, which is in my case). WP 4.5 introduced new filter "image_strip_meta" which can be used to keep or remove EXIF on generated resized images (medium and thumbnails).
Can this filter be used to keep EXIF in original image when function above for compressiong original image (which remove all EXIF data from original and all resized image version) is used?
Or, anything else which will result in compressing original image right after upload and keep EXIF in original image?
imagejpeg()
, so your problem has nothing to do with WordPress. See this (imagejpeg()
/GD library) and this (ImageMagick).image_strip_meta
doesn't apply to your code. Also, theimage_strip_meta
is only available if ImageMagick is installed.