/* Dateiverwaltung - File management in your browser Copyright (C) 2017 Ulrich Hilger, http://uhilger.de This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package de.uhilger.wbx; import java.io.File; import java.net.FileNameMap; import java.net.URLConnection; import java.util.logging.Logger; /** * Methoden zur Verkleinerung von Bildern */ public class Bild { private static final Logger logger = Logger.getLogger(Bild.class.getName()); public static final int WINZIG = 0; public static final int KLEIN = 1; public static final int SEMI = 2; public static final int MITTEL = 3; public static final int GROSS = 4; public static final String[] GRNAME = {"-w", "-k", "-s", "-m", "-g"}; public static final int[] GR = {120, 240, 500, 700, 1200}; public String imgType(String mimeType) { String imgType; if (mimeType.contains("jpg")) { imgType = "jpg"; } else if (mimeType.contains("jpeg")) { imgType = "jpg"; } else if (mimeType.contains("png")) { imgType = "png"; } else if (mimeType.contains("gif")) { imgType = "gif"; } else { imgType = "jpg"; } return imgType; } /** * * @param v Bild.WINZIG .. Bild.GROSS * @return Länge der längsten Kante in Bildpunkten */ public int getVariantenGroesse(int v) { return GR[v]; } public String getVariantenName(int v) { return GRNAME[v]; } public String getMimeType(File file) { String absName = file.getAbsolutePath(); FileNameMap fileNameMap = URLConnection.getFileNameMap(); return fileNameMap.getContentTypeFor("file://" + absName); } }