Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Member John Mc Grath's Avatar
    Join Date
    Sep 2011
    Location
    Ireland
    Posts
    80
    Member #
    29172
    Liked
    3 times
    Just wondering what is better, resizing an image from a previously used one or uplaoding as a new correct sized image. My site contains a lot of images and smaller versions of the same images. I was wondering if it slowed down or messed up web browsers making the changes. Is it better to upload two images, one original and one modified? I would use up much more server space and time if I was going to upload two images. Its just a thought and I was wondering if anyone had an opinion.
    Im pretty new to web design but I am learning fast. I will help if I can.
    Check out my sites http://www.mediareviewzone.com http://www.iamrobsmith.com

  2.  

  3. #2
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    Better for what ? Speed an efficiency ? Then yes, if you are serving up images that have not been sized correctly or have not been optimized, then reuploading the corrected images would always be better.

  4. #3
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    You can also upload one full-size image and when that image gets
    saved, a PHP script also creates a thumbnail of that image and
    saves that in a different directory. That makes it easier to upload
    images (you don't have to do double work), and it's faster when
    it runs ... to display the thumbnail instead of resizing it each time.

    This is my favorite resize function ...

    Taken from the PHP.net manual ...
    In this example, it takes the fullsize image, resizes it to
    a max width of 150 (you can specify that), and then
    saves that thumb in a different directory, but using the
    same filename. So, you call this function right after you
    save your full-size image.

    PHP Code:
    <?php


    resize
    ("my_photo.jpg"150"./thumbs/my_photo.jpg");

    echo 
    "done";


    function 
    resize($img$thumb_width$newfilename){
      
    $max_width=$thumb_width;

        
    //Check if GD extension is loaded
        
    if (!extension_loaded('gd') && !extension_loaded('gd2')){
            
    trigger_error("GD is not loaded"E_USER_WARNING);
            return 
    false;
        }

        
    //Get Image size info
        
    list($width_orig$height_orig$image_type) = getimagesize($img);
       
        switch (
    $image_type){
            case 
    1$im imagecreatefromgif($img); break;
            case 
    2$im imagecreatefromjpeg($img);  break;
            case 
    3$im imagecreatefrompng($img); break;
            default:  
    trigger_error('Unsupported filetype!'E_USER_WARNING);  break;
        }
       
        
    /*** calculate the aspect ratio ***/
        
    $aspect_ratio = (float) $height_orig $width_orig;

        
    /*** calulate the thumbnail width based on the height ***/
        
    $thumb_height round($thumb_width $aspect_ratio);
       

        while(
    $thumb_height>$max_width){
            
    $thumb_width-=10;
            
    $thumb_height round($thumb_width $aspect_ratio);
        }
       
        
    $newImg imagecreatetruecolor($thumb_width$thumb_height);
       
        
    /* Check if this image is PNG or GIF, then set if Transparent*/ 
        
    if(($image_type == 1) OR ($image_type==3))
        {
            
    imagealphablending($newImgfalse);
            
    imagesavealpha($newImg,true);
            
    $transparent imagecolorallocatealpha($newImg255255255127);
            
    imagefilledrectangle($newImg00$thumb_width$thumb_height$transparent);
        }
        
    imagecopyresampled($newImg$im0000$thumb_width$thumb_height$width_orig$height_orig);
       
        
    //Generate the file, and rename it to $newfilename
        
    switch ($image_type){
            case 
    1imagegif($newImg,$newfilename); break;
            case 
    2imagejpeg($newImg,$newfilename);  break;
            case 
    3imagepng($newImg,$newfilename); break;
            default:  
    trigger_error('Failed resize image!'E_USER_WARNING);  break;
        }
     
        return 
    $newfilename;
    }
    ?>

    .
    John Mc Grath likes this.


  5. #4
    Member John Mc Grath's Avatar
    Join Date
    Sep 2011
    Location
    Ireland
    Posts
    80
    Member #
    29172
    Liked
    3 times
    Some of my images are in three different sizes on the site. I haven't learned or used PHP yet but I am planning on learning it since its open source and everything but thanks for your advice. I think I will have to use it to finish my site if I want to make user accounts, comment boxes, and a search bar.
    Im pretty new to web design but I am learning fast. I will help if I can.
    Check out my sites http://www.mediareviewzone.com http://www.iamrobsmith.com

  6. #5
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    Then you call that function 3 times, changing the 150 to a variable, and changing the
    filename ... perhaps adding _1.jpg _2.jpg _3.jpg at the end of each one.


  7. #6
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    The way I handle it (using .NET, which has some similar functions to PHP for resizing images) is to take the largest image I can, resize it, and either do as mlseim suggested or save it as the same name, but in a different folder.

    The largest image part is the key. Resizing down is okay. Resizing up = bifurcated monkey rectum ugliness. (That's also your useless fact for the day...and gross one.)
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:36 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com