Search code examples
phphtmlimageresizeflickr

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 and I don't know how to do that.


Solution

  • 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">';
        ?>