Skip to content

Commit

Permalink
https://github.com/sterlp/svg2png/issues/11
Browse files Browse the repository at this point in the history
- added a way to force white background
  • Loading branch information
sterlp committed Jun 16, 2022
1 parent f557c57 commit 82777a0
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 205 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/sterl/svg2png/CliOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public enum CliOptions {
CONFIG("c", null, true, "JSON Config file for the file output."),
ALLOW_EXTERNAL("e", "allow-external", false, "Allow external entities to be loaded by the SVG."),

FORCE_TRANCPARENT_WHITE(null, "transparent-white", false, "This is a trick so that viewers which do not support the alpha channel will see a white background (and not a black one)."),

ANDROID(null, "android", false, "Android Icon 48dp mdpi 48x48 -> xxxhdpi 192x192."),
ANDROID_LAUNCH(null, "android-launch", false, "Android Launcher Icon config mdpi 48x48 -> xxxhdpi 192x192."),
ANDROID_ICON(null, "android-icon", false, "Android Icon (Action Bar, Dialog etc.) config mdpi 36x36 -> xxxhdpi 128x128."),
Expand Down Expand Up @@ -111,6 +113,9 @@ public static OutputConfig parse(CommandLine cmd) {
if (cmd.hasOption(ALLOW_EXTERNAL.longName)) {
result.setAllowExternalResource(true);
}
if (cmd.hasOption(FORCE_TRANCPARENT_WHITE.longName)) {
result.setForceTransparentWhite(true);
}
result.setInputFile(getValue(cmd, FILE));
result.setInputDirectory(getValue(cmd, FOLDER));
result.setOutputName(getValue(cmd, NAME));
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/sterl/svg2png/Svg2Png.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ private static List<File> convertFile(File input, OutputConfig cfg) throws IOExc

// Disable XXE
t.addTranscodingHint(SVGAbstractTranscoder.KEY_ALLOW_EXTERNAL_RESOURCES, cfg.isAllowExternalResource());
// https://github.com/sterlp/svg2png/issues/11
t.addTranscodingHint(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE, cfg.isForceTransparentWhite());


final List<File> generated = new ArrayList<>();
final String inputPath = input.getParent();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/sterl/svg2png/config/OutputConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ public class OutputConfig {
private String inputFile;
private String outputName;
private String outputDirectory;
/**
* https://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/transcoder/image/ImageTranscoder.html#KEY_FORCE_TRANSPARENT_WHITE
* PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE
*/
private boolean allowExternalResource = false;
private boolean forceTransparentWhite = false;

private List<FileOutput> files = new ArrayList<>();

Expand Down
Loading

0 comments on commit 82777a0

Please sign in to comment.