SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Dealing With Different User Image Sizes

    I am working on a membership site in which people can upload a company logo or personal photo.

    However I want to display the image in different sizes. Are there any techniques I can use to display different images in same orientation and scale?

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,213
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    I want to display the image in different sizes. Are there any techniques I can use to display different images in same orientation and scale?
    That sounds a bit contradictory, but anyhow ... you can set the width and height of images with CSS or even HTML, or you can set up the site with PHP to allow users to resize, crop and do other edits to images while they are uploading.

  3. #3
    SitePoint Member
    Join Date
    Aug 2012
    Location
    israel
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can decide the size of the images that wont change and stay the same size, you can ask for the up-loaders to use the size that will be correct, or you can limit the size of the uploaded image to a fix size.

  4. #4
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by canabatz View Post
    you can decide the size of the images that wont change and stay the same size, you can ask for the up-loaders to use the size that will be correct, or you can limit the size of the uploaded image to a fix size.
    Thanks so can I resize any image orientation so that it resizes properly without distorting?

  5. #5
    SitePoint Member
    Join Date
    Aug 2012
    Location
    israel
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not exactly but you can write some sentence that say: please upload image of size and size:y. and write the minimum size you want and max.
    and in css put the fixed size you want!

  6. #6
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    But wont that inconvene the user?

    Can PHP resize an image upon upload?

  7. #7
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,805
    Mentioned
    34 Post(s)
    Tagged
    2 Thread(s)
    OK, I think what is being said is that CSS and PHP are good.. but they can break the laws of physics.
    IF your user upload somethings that is not the right aspect ratio.. to what you want... there will always be either some cropping or some distortion ( this happens even if a human is doing the image manipulation) So your options are:

    1) ask the user to upload photos that are the correct size, or at least right aspect ratio.
    2) Allow the user to crop/resize the uploaded image so that it is to his liking BUT that it also fits the aspect ratio necessary
    3) scale the image using CSS knowing there will be some distortions of the images if they arent the correct aspect ratio.. and you may be wasting bandwith by loading unnecessarily large images.
    4) use PHP to scale the images to size knowing there will be some distortions of the images if they arent the correct aspect ratio.
    5) use PHP to crop the images knowing you may produce odd or unflattering crops.

  8. #8
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    What techniques do social networking sites such as Facebook or LinkedIn use? Or business directories in which people can add there own images.

  9. #9
    SitePoint Addict bimalpoudel's Avatar
    Join Date
    Feb 2009
    Location
    Kathmandu, Nepal
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Use CROPNAIL class

    Quote Originally Posted by justlukeyou View Post
    But wont that inconvene the user?

    Can PHP resize an image upon upload?
    You can use "cropnail" - where I crop the image from the center and resize it to requested thumbnail size.
    As long as your object is in the center, you will neither lose ratio nor lose the object.
    Link: class.cropnail.inc.php: http://smarty-framework.googlecode.c...opnail.inc.php

    Code:
    $cropnail = new cropnail(100, 200); # your target dimension
    $cropnail->resize($original_image_filename, $cropnail_image_filename, 0);
    This works irrespective of the dimension of your original image.
    I mean to say: You can get a vertical cropnail from a horizontally oriented image.
    To explain:
    You can have a 100x200 thumbnail from an image of 800x400 (see the changes in ratio).
    And you still prevent the image being distorted.

    This is not a normal way of creating thumbnails, but it works for me, hope for you too.
    Last edited by bimalpoudel; Aug 16, 2012 at 03:25. Reason: URL to cropnail class file added
    Bimal Poudel @ Sanjaal Framework over Smarty Template Engine
    ASKING INTERESTING QUESTIONS ON SITEPOINT FOURM

    Hire for coding support - PHP/MySQL


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
  •