Login Register


Resizing Mulitple Images at Once [Java] filter_list
Author
Message
Resizing Mulitple Images at Once [Java] #1
In The Name OF Allah
Al-Salam Alekum

A script for resizing images in Java:

PHP Code:
import java.awt.image.*; import java.awt.AlphaComposite; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; /* * @author LOL * */ public class ImageTest { private static final int IMG_WIDTH = 42; private static final int IMG_HEIGHT = 42; public static void main(String [] args){ try{ File folder = new File("Location of the folder"); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { BufferedImage img = ImageIO.read(listOfFiles[i]); int type = img.getType() == 0? BufferedImage.TYPE_INT_ARGB : img.getType(); BufferedImage resizeImagePng = resizeImage(img, type); ImageIO.write(resizeImagePng, "png", new File("c:\\image\\" + listOfFiles[i].getName())); } } }catch(IOException e){ System.out.println(e.getMessage()); } } private static BufferedImage resizeImage(BufferedImage originalImage, int type){ BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type); Graphics2D g = resizedImage.createGraphics(); g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null); g.dispose(); return resizedImage; } private static BufferedImage resizeImageWithHint(BufferedImage originalImage, int type){ BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type); Graphics2D g = resizedImage.createGraphics(); g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null); g.dispose(); g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); return resizedImage; } }


Wa Salam Alekum
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

Reply

RE: Resizing Mulitple Images at Once [Java] #2
Nice share my friend. Not really a fan of Java but usefull to know. Did you code this yourself?
~~ Might be back? ~~

Reply

RE: Resizing Mulitple Images at Once [Java] #3
(03-19-2018, 08:47 AM)Bish0pQ Wrote: Nice share my friend. Not really a fan of Java but usefull to know. Did you code this yourself?
Thank you my friend.
This script was for resizing an image but I edited it to resize multiple images at once.
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

[+] 1 user Likes Mr.Kurd's post
Reply







Users browsing this thread: 1 Guest(s)