Permalink
Browse files

Fixed pdf2image conversion with imagemagick on PDFs having transparency

The target image format (jpeg) doesn't support transparency, so the
Html2ImageTest produced unusable black images when ran on a linux
machine having imagemagick package installed.
  • Loading branch information...
luccioman committed Oct 16, 2017
1 parent 6e49724 commit 7c319c841e9194d1d19502a1802174559a5cabb0
Showing with 2 additions and 2 deletions.
  1. +1 −1 source/net/yacy/cora/util/Html2Image.java
  2. +1 −1 test/java/net/yacy/cora/util/Html2ImageTest.java
@@ -168,7 +168,7 @@ public static boolean pdf2image(File pdf, File image, int width, int height, int
try {
// i.e. convert -density 300 -trim yacy.pdf[0] -trim -resize 1024x -crop x1024+0+0 -quality 75% yacy-convert-300.jpg
// note: both -trim are necessary, otherwise it is trimmed only on one side. The [0] selects the first page of the pdf
String command = convert.getAbsolutePath() + " -density " + density + " -trim " + pdf.getAbsolutePath() + "[0] -trim -resize " + width + "x -crop x" + height + "+0+0 -quality " + quality + "% " + image.getAbsolutePath();
String command = convert.getAbsolutePath() + " -alpha remove -density " + density + " -trim " + pdf.getAbsolutePath() + "[0] -trim -resize " + width + "x -crop x" + height + "+0+0 -quality " + quality + "% " + image.getAbsolutePath();
List<String> message = OS.execSynchronous(command);
if (image.exists()) return true;
ConcurrentLog.warn("Html2Image", "failed to create image with command: " + command);
@@ -26,7 +26,7 @@ public static void setUpClass() throws Exception {
public void testPdf2image() {
// collect pdf filenames in test directory
File pd = new File("test/parsertest");
List<String> extensions = new ArrayList();
List<String> extensions = new ArrayList<>();
extensions.add("pdf");
FilenameFilter fileFilter = new ExtensionsFileFilter(extensions);
String[] pdffiles = pd.list(fileFilter);

0 comments on commit 7c319c8

Please sign in to comment.