commit | author | age
|
ca449e
|
1 |
/* |
U |
2 |
Dateiverwaltung - File management in your browser |
|
3 |
Copyright (C) 2017 Ulrich Hilger, http://uhilger.de |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
671a35
|
17 |
*/ |
ca449e
|
18 |
package de.uhilger.wbx; |
U |
19 |
|
|
20 |
import java.io.File; |
|
21 |
import java.net.FileNameMap; |
|
22 |
import java.net.URLConnection; |
35827a
|
23 |
import java.util.logging.Logger; |
ca449e
|
24 |
|
U |
25 |
/** |
|
26 |
* Methoden zur Verkleinerung von Bildern |
|
27 |
*/ |
|
28 |
public class Bild { |
671a35
|
29 |
|
35827a
|
30 |
private static final Logger logger = Logger.getLogger(Bild.class.getName()); |
U |
31 |
|
ca449e
|
32 |
public static final int WINZIG = 0; |
U |
33 |
public static final int KLEIN = 1; |
91d228
|
34 |
public static final int SEMI = 2; |
U |
35 |
public static final int MITTEL = 3; |
|
36 |
public static final int GROSS = 4; |
671a35
|
37 |
|
91d228
|
38 |
public static final String[] GRNAME = {"-w", "-k", "-s", "-m", "-g"}; |
U |
39 |
public static final int[] GR = {120, 240, 500, 700, 1200}; |
ca449e
|
40 |
|
U |
41 |
public String imgType(String mimeType) { |
|
42 |
String imgType; |
671a35
|
43 |
if (mimeType.contains("jpg")) { |
ca449e
|
44 |
imgType = "jpg"; |
671a35
|
45 |
} else if (mimeType.contains("jpeg")) { |
ca449e
|
46 |
imgType = "jpg"; |
671a35
|
47 |
} else if (mimeType.contains("png")) { |
ca449e
|
48 |
imgType = "png"; |
671a35
|
49 |
} else if (mimeType.contains("gif")) { |
ca449e
|
50 |
imgType = "gif"; |
U |
51 |
} else { |
|
52 |
imgType = "jpg"; |
|
53 |
} |
|
54 |
return imgType; |
|
55 |
} |
671a35
|
56 |
|
ca449e
|
57 |
/** |
671a35
|
58 |
* |
ca449e
|
59 |
* @param v Bild.WINZIG .. Bild.GROSS |
U |
60 |
* @return Länge der längsten Kante in Bildpunkten |
|
61 |
*/ |
|
62 |
public int getVariantenGroesse(int v) { |
|
63 |
return GR[v]; |
|
64 |
} |
671a35
|
65 |
|
ca449e
|
66 |
public String getVariantenName(int v) { |
U |
67 |
return GRNAME[v]; |
|
68 |
} |
671a35
|
69 |
|
ca449e
|
70 |
public String getMimeType(File file) { |
U |
71 |
String absName = file.getAbsolutePath(); |
|
72 |
FileNameMap fileNameMap = URLConnection.getFileNameMap(); |
671a35
|
73 |
return fileNameMap.getContentTypeFor("file://" + absName); |
ca449e
|
74 |
} |
U |
75 |
} |