Validate that uploaded image DPI and size is printable
My web application requires users to upload a passport-style photo of themselves. This photo will be used to generate several images:
- web avatars of multiple sizes to display within the application (72 dpi)
- printable image to print a 1"x1" face shot using an ID card printer (300 dpi)
- printable image to print in reports on a standard printer (300+ dpi)
I'm going to use a jquery-based image cropping tool (perhaps JCrop) so that the user can select an area just around their face a开发者_如何学运维nd disregard the rest of the image.
Are there any techniques to make sure that the image that is uploaded is of high enough resolution that it can be printed to the card printer and regular printers with a dimension of at least 1" x 1"?
My understanding is that EXIM dpi information is not reliable. Should I simply verify that the size they select in the crop equates to at least 300x300 pixels in the raw image?
Would it be best to handle this on the client in javascript or on the server (which is using Java)?
Well if you want to make sure the image resolution is big enough so that it can be printed at 300dpi with a good quality you just need to make sure that the part that is being selected by the user.
After having a quick look on JCrop it seem like you can access the coordinates of the selected image part easily (using showCoords() ).
With that you know the size of the selected image parts in pixels. It now depends on how big you want to print your image with 300dpi.
Therefore for i.e. an US Letter at 300dpi it needs to be 2550x3300px. For DIN A4 it would be 2480x3508 pixels.
So out of the coordinates you get from JCrop simply calculate how big the rectangle dimensions are in pixels and check if it's big enough to be printed to the size you desire at 300dpi...
Hope that helps...
Edit:
If you want to make sure the image is correct, by which I mean it has a face that fills about 80% of the image you could try using a python script that uses OpenCV... OpenCV already provides basic face detection algorithms. So maybe you can have the uploaded image run through the face detection algorithm which then says whether it contains a face or not...
精彩评论