WordPress.org

Ready to get started?Download WordPress

Forums

PHP Black and White images (1 post)

  1. vikkineal
    Member
    Posted 2 years ago #

    Hi can anyone help.

    I found the following code online to enable me to add b&w images to my wordpress site without having to create them manually.

    It was working fine, but now all of a sudden I'm getting an error when trying to upload an image.

    The error says:

    "Warning: imagefilter() expects parameter 1 to be resource, string given in /homepages/31/d391121670/htdocs/byr/wp-content/themes/britishyachtregistrations/functions.php on line 26
    189"

    The function is:

    // black and white images
    
    add_action('after_setup_theme','themename_bw_size');
    function themename_bw_size() {
    	add_image_size('bw-image', 180, 180, true);
    }
    
    add_filter('wp_generate_attachment_metadata','themename_bw_filter');
    function themename_bw_filter($meta) {
    	$file = wp_upload_dir();
    	$file = trailingslashit($file['path']).$meta['sizes']['bw-image']['file'];
    	list($orig_w, $orig_h, $orig_type) = @getimagesize($file);
    	$image = wp_load_image($file);
    	imagefilter($image, IMG_FILTER_GRAYSCALE);
    	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;
    }

    Any ideas would be greatly appreciated.

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic