开发者

Resize content of HTML image markup with PHP

My HTML page displays an image with the following code (using Flickr)

    <?php
    echo '<img src="http://farm' . $photo["farm"] . '.static.flickr.com/' . $photo["server"] . '/' . $photo["id"] . '_' . $photo["secret"] . '.jpg">';
    ?>

The thing is that I'd like to resize this image to then display it on the page an开发者_JAVA百科d I don't know how to do that.


Often sites such as flickr allow you to request different sized versions of the image so your best bet is likely to be to request an appropriately sized image.

I'm not sure of the exact details but I looked at http://www.flickr.com/photos/29609591@N08/5735893153/sizes/z/in/photostream/ (a photo I found on the front page of the site) and there are links to different sizes. They seem to be in the same form as yours with the addition of _x just before the .jpg (where x is a letter dependant on size).

I couldn't find any documentation on this in a quick search but in this case we had:

_s for a square
_t for a thumbnail
_m for a small
(no extension) for a medium 500
_z for a medium 640
_b for a large
_o for original - this url seems to be different from the others

I suspect the criteria for these is by fitting to an upper limit of dimensions but I don't know for sure. Trial and error may help you out.


Add width and height attributes to your html string.

<?php
    echo '<img width='200px' height='200px' src="http://farm' . $photo["farm"] . '.static.flickr.com/' . $photo["server"] . '/' . $photo["id"] . '_' . $photo["secret"] . '.jpg">';
    ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜