2

I have a set of images (url addresses). Some of them are of acceptable size, but some are too big. When I load it, the app crashes because of big images.

Is there a way to get the image size (megabytes) before loading it? This way I can remove large images from the list, and avoid loading them.

kuporific
  • 10,053
  • 3
  • 42
  • 46
Constantine
  • 83
  • 11
  • If you have access to server, maybe you could resize image to maximum allowed size at image upload and then you would have all images same size with, let's say, http://stackoverflow.com/questions/8819524/a-very-good-php-image-resize-script-suggestion. I used similar way in my project from year and half ago and has been working since then perfectly. I think (my humble opinion) that this is something client should not worry about. It is server's task to prepare "valid" data for client. – KernelPanic Apr 20 '15 at 15:35
  • 1
    yes, you are right. An idea to remove large images from load list is a temporary crutch. In the future it will in the way you advice. – Constantine Apr 21 '15 at 07:38

1 Answers1

2

If the server where the images are located supports it, you can issue a HEAD request. This can be done in Qt using e.g. QNetworkAccessManager::head.

It should also be possible in QML/Javascript, see HTTP HEAD Request in Javascript/Ajax?.

Community
  • 1
  • 1
m.s.
  • 16,063
  • 7
  • 53
  • 88
  • 1
    I wouldn't like to do it in Qt/c++ , because there is a cute implementation with plain QML :-) But thanks for reply, I'll try it! – Constantine Apr 20 '15 at 14:29