简体   繁体   中英

Determine the size of an image using ImgScalr

Hi I am currently using ImgScalr library and I have few markers to download images from an HTML document , however sometimes the images are of low quality,and if they are then I need to scan thru the html source to download all the images and use the one with the biggest size in bytes.

I use ImgScalr library, I need to know how I can check the size of the image in bytes to determine if it meets my quality requirements. Is it the right approach?

Thanks.

imgscalr author here - the library is focused on image operations only, operating on the uncompressed BufferedImage objects.

To know the actual file size you would just download all the images from the HTML page to a directory and then iterate through the files using the standard Java File operations to determine the file size.

If you are using Java 7+ you can use the handy Files.size operation.

$dir = "/path/to/image/directory/*.jpg";   //Path to image folder and image type extension
$list = array();                           //Create and empty array

foreach(glob($dir) as $checkimages){
  $size = filesize($checkimages);
  if($size > 500000){                      //enter file size minimum
     $list[] = $checkimages;                //final array contains the images you seek
  }
}

This uses PHP to find all images in a folder, then checks each for a minimum files size, if meets criteria inserts into new array.

//Output to HTML each file in array
foreach($list as $output){
    echo $output.'<br/>';
}

// or 
print_r($list);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM