image_get_intermediate_size partly ignores 'path' and 'url' fields and has inconsistent return values
|Reported by:||whoismanu||Owned by:|
the current implementations of image_get_intermediate_size and image_downsize in wp-includes/media.php have several inconsistencies.
image_get_intermediate_size() returns the following information about an attachment for registered sizes: file, width, height, path, url. for ad-hoc sizes (if the size argument is an array) it returns: file, width, height.
in the second case, path and url information that may have been set by a plugin is lost.
further, the calling function, image_downsize(), in any case regenerates the url like this
$img_url = str_replace(basename($img_url), $intermediate['file'], $img_url);
this means that now also for the registered sizes, the 'url' information is discarded. further, this means that for registered sizes, the url is computed twice, once inside image_downsize as detailed above, once in image_get_intermediate_size() like this
$data['url'] = path_join( dirname($file_url), $data['file'] );
to me, a cleaner approach would be to return the full information (file, width, height, path, url) independent of whether an image size is registered or not. all these fields can then also be directly calculated inside image_get_intermediate_size() and the caller does not have to bother with, e.g., generating paths and urls. further, this would allow to accept path and url information that is already present in the db, also in the case of ad-hoc image sizes.
i put together a patch that provides a potential solution.