Skip to content

Add support for heic/heif (IOS) image format #3029

Description

@nicolaslimet

That would allow users to upload images takjen on IOS devices, provided the server has the right setup.

Example implementation with hooks:

add_action( 'geodir_after_post_attachment_upload', 'gdsnippet__987gfHtd5d6g_allow_heic' );
function gdsnippet__987gfHtd5d6g_allow_heic( $file ) {
    $mime = wp_get_image_mime( $file['file'] );

    if ( 'image/heic' !== $mime && 'image/heif' !== $mime ) return;

    $imagesize = wp_getimagesize( $file['file'] );

    $output_format  = wp_get_image_editor_output_format( $file, $imagesize['mime'] );
    $convert        = false;
	if (
		is_array( $output_format ) &&
		array_key_exists( $imagesize['mime'], $output_format ) &&
		$output_format[ $imagesize['mime'] ] !== $imagesize['mime']
	) {
		$convert = true;
	}

    if ( ! $convert ) return;

    $editor = wp_get_image_editor( $file['file'] );

    if ( is_wp_error( $editor ) ) {
		return;
	}

    $convert = $editor->save( $editor->generate_filename( '' ) );
    
    if ( is_wp_error( $convert ) ) return;

    add_filter( 'geodir_media_attachment_file_url', function( $url ) {
        return str_replace( [ '.heic', '.heif' ], '.jpg', $url );
    }, 999, 1 );
}

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions