• Resolved madmax4ever

    (@madmax4ever)


    Hello,
    I just noticed that the medium_large WordPress size seems not be registered globally. It seems this size is generated automatically when needed.
    As a result, it can be found in the attachement’s sizes array, but WPPP do not recognize this size (it’s not set in its specific option containing WPPP known sizes).
    So I had to modify function serve_image so that in the try statement, if WPPP do not find a valide size, a secpnd chance it taken as follow:

    // 2ND CHANCE START - Try to get attachement's specific sizes
    if ( $the_size === '' ) {
    	$size_pattern = '/-[0-9]+x[0-9]+\.(jpe?g|png|gif)/';
    	$repl_pattern = '.$1';
    	$request_uri = $_SERVER['HTTPS'] ? 'https://' : 'https://';
    	$request_uri .= $_SERVER['SERVER_NAME'];
    	$request_uri .= preg_replace ($size_pattern, $repl_pattern, $request);
    	$postid = attachment_url_to_postid($request_uri);
    	if ( $postid > 0 ) {
    		$meta_d = wp_get_attachment_metadata($postid);
    		$sizes = $meta_d['sizes'];
    		foreach ( $sizes as $size => $size_data ) {
    			// always check, even if size is in meta data, as the size could have changed since it was saved to meta data
    			$new_size = image_resize_dimensions( $imgsize[ 'width' ], $imgsize[ 'height' ], $size_data[ 'width' ], $size_data[ 'height' ], $size_data[ 'crop' ] );
    			if ( ( abs( $new_size[ 4 ] - $this->width ) <= 1 ) && ( abs( $new_size[ 5 ] - $this->height ) <= 1 ) ) {
    				// allow size to vary by one pixel to catch rounding differences in size calculation 
    				$the_size = $size;
    				$crop = $size_data[ 'crop' ];
    				break;
    			}
    		}
    	}
    }
    // 2ND CHANCE END

    I know it may not be the proper solution, but this kludge manages the 768x… medium_large size some images have.

    I’m sure you’ll find a better way to do that.
    Just to share and help your plugin improve. ??

    Thank you

    The page I need help with: [log in to see the link]

  • The topic ‘Size medium_large not managed’ is closed to new replies.