Skip to content

Commit

Permalink
Fixed pdf2image conversion with imagemagick on PDFs having transparency
Browse files Browse the repository at this point in the history
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 7c319c8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/net/yacy/cora/util/Html2Image.java
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/java/net/yacy/cora/util/Html2ImageTest.java
Expand Up @@ -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);
Expand Down

0 comments on commit 7c319c8

Please sign in to comment.