How do you create a thumbnail image out of a JPEG in Java?

Image img = ImageIO.read(new File(“test.jpg”)).getScaledInstance(100, 100, BufferedImage.SCALE_SMOOTH); This will create a 100×100 pixels thumbnail as an Image object. If you want to write it back to disk simply convert the code to this: BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); img.createGraphics().drawImage(ImageIO.read(new File(“test.jpg”)).getScaledInstance(100, 100, Image.SCALE_SMOOTH),0,0,null); ImageIO.write(img, “jpg”, new File(“test_thumb.jpg”)); Also if you are concerned about speed … Read more

Unable to read JPEG image using ImageIO.read(File file)

Old post, but for future reference: Inspired by this question and links found here, I’ve written a JPEGImageReader plugin for ImageIO that supports CMYK color models (both with original color model, or implicitly converted to RGB on read). The reader also does proper color conversion, using the ICC profile embedded in the JPEG stream, in … Read more

Is there a way to tell browsers to honor the jpeg exif orientation?

CSS image-orientation: from-image from the specs https://www.w3.org/TR/css4-images/#the-image-orientation 6.2. Orienting an Image on the Page: the ‘image-orientation’ property image-orientation: from-image from-image: If the image has an orientation specified in its metadata, such as EXIF, this value computes to the angle that the metadata specifies is necessary to correctly orient the image. If necessary, this angle is … Read more

Setting jpg compression level with ImageIO in Java

A more succinct way is to get the ImageWriter directly from ImageIO: ImageWriter jpgWriter = ImageIO.getImageWritersByFormatName(“jpg”).next(); ImageWriteParam jpgWriteParam = jpgWriter.getDefaultWriteParam(); jpgWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); jpgWriteParam.setCompressionQuality(0.7f); ImageOutputStream outputStream = createOutputStream(); // For example implementations see below jpgWriter.setOutput(outputStream); IIOImage outputImage = new IIOImage(image, null, null); jpgWriter.write(null, outputImage, jpgWriteParam); jpgWriter.dispose(); The call to ImageWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) is needed in order to explicitly set … Read more

In OpenCV (Python), why am I getting 3 channel images from a grayscale image?

Your code is correct, it seems that cv2.imread load an image with three channels unless CV_LOAD_IMAGE_GRAYSCALE is set. >>> import cv2 >>> image = cv2.imread(‘foo.jpg’) >>> print image.shape (184, 300, 3) >>> gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) >>> print gray_image.shape (184, 300) >>> cv2.imwrite(‘gray.jpg’, gray_image) Now if you load the image: >>> image = cv2.imread(‘gray.jpg’) >>> … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)