I'm building a crawler and i need to get the height and the width of a remote image (or multiple images). I'm already doing that with threads - but still this is the task consuming most of the time:
//Start threadppol
ExecutorService imageExecutorService = null;
List<Future<ImageModel>> futureImages = null;
if (imageSize > 0) {
imageExecutorService = Executors.newFixedThreadPool(4);
futureImages = new ArrayList<>();
int counter=0;
for (Image imgUrl : imgUrls) {
Callable<ImageModel> callable = new ExtractImages(imgUrl,hostUrl);
Future<ImageModel> future = imageExecutorService.submit(callable);
futureImages.add(future);
if(counter>=4){
break;
}
counter++;
}
}
ExtractImages class:
// Get the image
BufferedImage image = ImageIO.read(new URL(hostUrl, extractedImage.getSrc()));
So i'm using kind of the standard way to do it in Java (ImageIO.read(url)). The question is, is there a better way to get the height and with of an image from an imageurl?