SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2013
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Resize image using the URL

    Hello,

    I started a thread a while ago about resize an image to a container without the image losing its aspect ratio - link to the thread"

    I tried to achieve this using CSS which I did manage to do. However, CSS didn't seem to do it very elegantly and displays differently in different browsers.

    So what I want to do is resize an image to its parent div size which is 174x217px. The image should remain good quality, resize quickly and not have any of the image overflowing or being cut off. I've seen many sites resizing the image by using the URL. The default example on this page is something i'm looking for here.

    The url to the image would be something like this mywebsite.com/images/testimage.png?width=174&height=217

    Any suggestions?

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,407
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    You can do it with GD or imagemagick; years ago I found a piece of code that would do it via the .htaccess file but that is long gone from my PC.

    A couple of Imagemagick methods from memory is best to put these codes on separate pages and call with <img src="php_code.php">:

    PHP Code:
    <?php 
    $photo
    ="sunflower.jpg"

    $cmd "convert $photo -thumbnail 200x200 "
    " -unsharp 0.2x0.6+1.0 -quality 100 JPG:-"

    header("Content-type: image/jpeg"); 
    passthru($cmd$retval); 
    ?>  

    // There can not be any code before this:
    <?php 
    system
    ("convert ../code/sunflower.jpg -resize 200x200 JPG:-"); 
    ?>

  3. #3
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,407
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    This was the website I found the .htaccess method code on.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •