Blurred Image

/**
 * Register Blurred Image Size
 *
 */
function ea_register_blurred_image_size() {
  add_image_size( 'header_blurred', 1200, 400, true );
}
add_action( 'after_setup_theme', 'ea_register_blurred_image_size' );

/**
 * Blur Image on Save
 *
 */
function ea_blur_image_on_save( $meta, $attachment_id ) {
	$blur_amount = 15;
    $file = wp_upload_dir();
    $file = trailingslashit($file['path']).$meta['sizes']['header_blurred']['file'];
    list($orig_w, $orig_h, $orig_type) = @getimagesize($file);
    $image = wp_load_image($file);
	for( $i = 0; $i < $blur_amount; $i++ ) {
    	imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
	}
    switch ($orig_type) {
        case IMAGETYPE_GIF:
            imagegif( $image, $file );
            break;
        case IMAGETYPE_PNG:
            imagepng( $image, $file );
            break;
        case IMAGETYPE_JPEG:
            imagejpeg( $image, $file );
            break;
    }
    return $meta;
}
add_filter( 'wp_generate_attachment_metadata', 'ea_blur_image_on_save', 10, 2 );
Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk