Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts

    How can I check the size of an image ?

    Hi,

    I want to check the size of an image file
    before I write it.

    If it is a certain size, then I won't write it.

    Can I check the future size of the file by
    using strlen() on the file_get_contents($url); ?

    Here is my script:

    First I get the image from an image website,
    but if the image is the standard error image ( "Can't find image" ),
    then I don't want to save it:

    ( The size of this standard error image is always 4.49Kb )

    PHP Code:
    $image_data file_get_contents($url);

    IF( 
    strlen($image_data) != ?? ) {  //   don't know what this should be

      
    if($image_data === FALSE) {
        
    write_log("$ctr )$id PROBLEM with READ \r\n");    
        }
      else {
        
    write_log("$ctr )Processing $image_loc \r\n");
        
    $file_size file_put_contents($image_loc$image_data);
        if(
    $file_size  === FALSE) {
            
    write_log("$ctr )$id PROBLEM with WRITE \r\n");
        }
        else {
        
    write_log("$ctr )$id Image created size : $file_size\r\n");         
        }
      }
     }  
    // END IF 
    Or is there a better way to do this ?

    The other thing I could do is write the file with the
    file_put_contents() then check the file size, then delete if
    it is the "standard" size. But that seems a waste of resources.

    Any ideas ?


    .
    Last edited by jeddi; 03-14-2010 at 07:32 PM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Size? Do you mean filesize, or W X H (dimension) size?

    Filesize:
    http://php.net/manual/en/function.filesize.php

    Image dimensions:
    http://php.net/manual/en/function.getimagesize.php

    Example:
    // Get new dimensions
    list($width, $height) = getimagesize($filename);
    Last edited by mlseim; 03-15-2010 at 03:33 AM.

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks for reply,

    Maybe I was not clear.

    I am using an image serving service, and if it can not create the image
    then it serves a "standard" "Can't Create Image" image and returns that.

    It then queues the image for later recovery. So I am not meaning the 404 page
    but their standard "Can't Create Image" image"

    Now if it serves that image, then I do not want to store it because my
    script will then think that we have the correct image available.

    I know what filesize() does, I would just like to know if there is way
    of finding the size of the file before it is written by looking at the size of
    the string that holds the file data from file_get_contents().

    Maybe I have to store the image first file_put_content() and then check its
    filesize() and then delete it with unlink().

    I was just trying to avoid the unnecesary steps by checking first.

    Hope that explains it more fully




    .
    Last edited by jeddi; 03-15-2010 at 07:24 AM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.


  •  

    Posting Permissions

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