• Resolved Xaliber

    (@xaliber)


    I got this when I tried adding a featured image using smart crop.

    Warning: Illegal offset type in isset or empty in D:\xampp\htdocs\youthproactive\wp-content\plugins\wp-smartcrop\wp-smartcrop.php on line 480

    Not sure what the problem here. And the pic displayed doesn’t seem to be smart cropped. If I may ask, how does this plugin work exactly? Does the smart cropping save the cropped image somewhere, or is it displayed on the fly?

Viewing 4 replies - 1 through 4 (of 4 total)
  • I am experiencing the same problem here. Help!

    “/home/wasanzie/www/wasanziehen.com/wp-content/plugins/wp-smartcrop/wp-smartcrop.php on line 480”

    sorry for the late response. I think this is a warning that gets sent when the “size” parameter isn’t set by the image in question… I have pushed a point update that attempts to deal with this as an edge case, but I haven’t been able to reproduce the problem on my installs, so it’s a best guess for now. If you’re willing to try again, let me know if things change… also, theme names, wordpress version, and any plugins installed could help me further reproduce.

    I’m just probably (for me it’s in line 468, but that may be caused by script updates) looking at this error. I get this error message on the Media List page where WordPress shows a 60×60 image preview, using a 150×150 source file:

    The error occurs when calling function get_smartcrop_focus_attr(2601, array(60,60)). Note the array as second parameter. This second parameter is checked in is_image_size_cropped(), which returns false, thus allowing the function get_smartcrop_focus_attr to proceed to line 468:

    $this->focus_cache[ $id ][ $size ] = $ret_val;

    $size still contains array(60, 60) which causes the warning (and possibly some other unexpected results).

    As a simple solution I went to make sure I have a valid array key:

    $size_str = is_array($size) ? implode('::', $size) : $size;

    … and then use $size_str in all three locations where $size was referenced as a key for focus_cache.

    		private function get_smartcrop_focus_attr( $id, $size ) {
    			$size_str = is_array($size) ? implode('::', $size) : $size;
    
    			// check cache
    			if( isset( $this->focus_cache[ $id ] ) && isset( $this->focus_cache[ $id ][ $size_str ] ) ) {
    				return $this->focus_cache[ $id ][ $size_str ];
    			}
    			if( !$this->is_image_size_cropped( $size ) ) {
    				if( get_post_meta( $id, '_wpsmartcrop_enabled', true ) == 1 ) {
    					$focus = get_post_meta( $id, '_wpsmartcrop_image_focus', true );
    					if( $focus && is_array( $focus ) && isset( $focus['left'] ) && isset( $focus['top'] ) ) {
    						$ret_val = json_encode( array(
    							round( intval( $focus['left'] ), 2 ),
    							round( intval( $focus['top' ] ), 2 ),
    						) );
    						// load into cache
    						if( !isset( $this->focus_cache[ $id ] ) ) {
    							$this->focus_cache[ $id ] = array();
    						}
    
    						$this->focus_cache[ $id ][ $size_str ] = $ret_val;
    						return $ret_val;
    					}
    				}
    			}
    			return false;
    		}

    This should be fixed in the latest version. Actually, array sizes should be set as cropped by default, and should never hit that code, as we can’t know for sure what size wordpress will return without further processing.

    I’ll see if they need to be revisited at a future date.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Illegal offset type in isset or empty’ is closed to new replies.