The algorithm:
- Get the URL for the photo.
- Parse the URL into its component parts (scheme, host, path, filename).
- Inject the thumbnail qualifier before the filename.
- Reassemble the component parts.
For example:
// Define thumbnail properties (w = width, 200 = pixels).
$THUMBMAIL = "w200";
// Get the "source" URL for the image.
$imgSrc = $photoEntry->content->getSrc();
// Extract the component parts.
$url = parse_url( $imgSrc );
// Extract the path and inject the thumbnail size.
$url["path"] = dirname( $path ) . "/$THUMBNAIL/" . basename( $path );
// Reassemble the URL.
$thumbnail = build_url( $url );
You should be able to use http_build_url, but I had naming conflicts, so wrote this:
function build_url( $url ) {
return $url["scheme"] . "://" . $url["host"] . "/" . $url["path"];
}
Read this article for more details.