3

I want to be able to prevent users from uploading low quality images to my website.

I'd thought about doing this through restricting DPI thresholds, but it seems this isn't too easy to do.

Does anyone know any tricks to do this? I'm happy for it to be imprecise, i.e. a modelled DPI, or occasionally wrong. Also happy for it to only apply to some image types.

Basically anything to improve the user generated content would help!

Ideally the solution will be in Java, but I'll consider any tech, as long as it can be wrapped in a web service.

John
  • 6,503
  • 3
  • 37
  • 58
laura
  • 2,951
  • 9
  • 44
  • 61
  • Did you want C# tagged or is this just for Java? – John Jan 24 '12 at 18:34
  • You'll probably want to look at this question: [how to get the dpi of an image](http://stackoverflow.com/questions/7142568/how-to-get-the-dpi-of-an-imagejava) – John Jan 24 '12 at 18:35
  • 1
    Or you can use the Sanselan of the commons.apache.org to get the info http://www.ashishpaliwal.com/blog/2009/07/apache-sanselan-retrieving-image-information-using-sanselan/ or http://commons.apache.org/sanselan/api-release/org/apache/sanselan/Sanselan.html – Sergey Benner Jan 24 '12 at 18:53
  • @John yes, c# too - I'm happy to develop in anything. And I saw that question - but the code answer is ripped from a really old post, and doesn't work. And I haven't been able to find an ImageMagick call to do the work. – laura Jan 24 '12 at 19:40
  • @sergey, thanks, that looks interesting, I hadn't seen that one before. – laura Jan 24 '12 at 19:41
  • aye np. apache's commons has become pretty much standard library already. – Sergey Benner Jan 24 '12 at 19:45
  • Are you going after image "quality", or image size? DPI by definition depends on the medium in which it's being displayed, which would be fixed (ish) on a monitor. Photos, or arbitrary images? Over compression? What are you actually trying to filter out? – James Jan 24 '12 at 20:36
  • These are product photos, uploaded by the designers. We need them to be magazine-print quality. And whilst we can review - it would be better to have some low quality ones filtered out from the start. – laura Jan 24 '12 at 20:48

1 Answers1

3

Did you try following API's to acheive this ?

com.sun.image.codec.jpeg com.sun.media.jai.codec

Here is the sample code

import java.net.MalformedURLException;
import java.net.URL;

import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;

class CheckResolution {
  String imageURL = "test.png";

  public static void main(String[] args) throws MalformedURLException {
     CheckResolution cr = new CheckResolution();
     URL imageurl = new URL(cr.imageURL);
     PlanarImage pi = JAI.create("url", imageurl);
     int imagewidth = pi.getWidth();
     int imageheight = pi.getHeight();
     System.out.println("Image Width:" + imagewidth + " --- Image Height:" + imageheight);
  }
}
user47900
  • 647
  • 4
  • 6
  • another dpi related post : http://stackoverflow.com/questions/6390964/decrease-image-resolution-in-java – user47900 Jan 24 '12 at 18:57
  • Thanks for your answer - I'm going to try it as soon as I get the jai extensions installed on my work machine. – laura Jan 24 '12 at 19:55