Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Png images contain random noise pixels #2629

Open
nitrousdigital opened this issue Oct 14, 2015 · 19 comments
Open

Png images contain random noise pixels #2629

nitrousdigital opened this issue Oct 14, 2015 · 19 comments
Labels

Comments

@nitrousdigital
Copy link

nitrousdigital commented Oct 14, 2015

I am generating a small png image from a simple html file and the resulting png file contains random noise pixels in the first line of the image. All of the attached images were generated from the same exact html file using the command-line:

wkhtmltoimage.exe --transparent --javascript-delay 500 error.html error_out.png

error_out14
error_out16

The content of error.html file is as follows:

<html>
<head>
    <style>
        body {
            margin:0px;
            background-color:white;
        }
        .kpi-error-icon {
            margin-right: 5px;
            vertical-align: middle;
        }
        .kpi-error-grid {
            background-color: #FFE6E6;
            border-radius:10px;
            padding: 10px;
        }
        .kpi-error-grid td {
            font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
            font-size:12px;
        }
        .kpi-error-title {
            font-weight:bold;
            font-size:14px !important;
            white-space: nowrap;
            color: red;
            vertical-align : middle;
        }
        .kpi-error-message {
            font-weight:bold;
            font-size:12px;
            color: black;
        }
    </style>
</head>
<body>
    <table class='kpi-error-grid' id='layout-table' border='0' cellspacing='0' cellpadding='5' >
    <tbody>
        <tr>
            <td class='kpi-error-title' align='center'>Error!</td>
        </tr>
        <tr>
            <td class='kpi-error-message' align='center'>Failed to build metric chart set &quot;Variance_1_RawMetricData&quot;: Unable to retrieve kpi data.</td>
        </tr>
    </tbody>
    </table>
</body>
</html>

I'm using:
wkhtmltoimage 0.12.2.4 (with patched qt)
Windows 7 Professional SP 1 64-bit

@nitrousdigital
Copy link
Author

Note: This problem only occurs when generating images with a transparent background (using the --transparent option)

@ryana
Copy link

ryana commented Oct 26, 2015

Same issue:

Pie chart

Image isn't loading, not sure why. Here is link: https://ramen-files.s3.amazonaws.com/email-images/a03fac7a-4c07-459c-94a3-6a5bb34d374e.png

wkhtmltoimage 0.12.1 (with patched qt)
OSX Yosemite

@ericfirth
Copy link

@ryana
Copy link

ryana commented Nov 3, 2015

Btw, this happens at 200x200, but not at 220x200. At 190x190, only the bottom ~20% of the image has noise. One of the odder bugs I've encountered. I only need PNGs, so I've moved over to a PhantomJS-based solution (https://github.com/ramen-dev/screencap) but still interested in this getting fixed for future PDF exports.

@kazimzaidi
Copy link

+1 happens with me. Happens when one of the images on the page has a size > 800kb.

@micheal-swiggs
Copy link

+1 I'm getting this error when using both the --transparent and --width flags. I've created some html for my problem: https://gist.github.com/micheal-swiggs/13aac40efb57d8a7bd0f

@pjarmalavicius
Copy link

pjarmalavicius commented Nov 29, 2017

What is the status of this issue? I have same issue and want to know how to solve it

@Tim-Brenner
Copy link

I've found a workaround for this! The solution I figured out through trial-and-error is to set the width to something rather large. In my case, I set it to 8000. It apparently only uses the width as a guideline, so this theoretically should be a safe solution.

@Tomsgu
Copy link
Contributor

Tomsgu commented Aug 23, 2018

Is this still an issue in 0.12.5?

@franjaviersans
Copy link

I was able to isolate the issue.

Qt images are initialized with uninitialized data, as stated in -> http://doc.qt.io/qt-5/qimage.html#QImage-1

A line with "image.fill(qRgba(0, 0, 0, 0));" should be added after the initialization of the image to ensure that some data will always be on the background. This will fix issues with images with transparent background.

@Xhilbert
Copy link

Thank you franjaviersans !

I have just downoaded the latest version of wkhtmlimage and the bug is still there.
I don't know how to build the wkhtm library. Could someone use your idea to fix the bug, and upload the fixed release version of wkhtml on github ?

thank you.
Xavier.

@franjaviersans
Copy link

Hello @Xhilbert I can give you the steps to build it, but I don't know how to upload the new version:

The source code can be changed adding "image.fill(qRgba(0, 0, 0, 0));" in the line 182 of the file imageconverter.cc, after the creation of the image.
I generated the file with the version 0.12.5 of the library.

To build the library the following steps should be used:

  • Install virtual machine with Ubuntu or use a native Ubuntu OS. If a virtual machine is going to be used, install VMware Workstation instead of VirtualBox, as the latter doesn't allow the use of docker on the guest OS.
  • Pull repository (with submodules) of the source code from https://github.com/wkhtmltopdf/wkhtmltopdf (commit cb88e4e)
  • Pull repository containing the packaging tool from https://github.com/wkhtmltopdf/packaging (commit 1a23e08) and install the listed programs on Ubuntu
  • Run the following command on the console: sudo ./build package-docker mxe-cross-win64 ../wkhtmltopdf/
  • All the files required to run the library can be found on the "targets" folder

I only built it for that windows versions. There is the possibility to build with other platforms, but not all of them worked for me.

Hope it helps.

Let me know if you are able to build and upload a new version, as I'm currently using my modified version, but I would like to use the official version.

@Galigator
Copy link

Using your explanation, I was able to compile and release (a non official) a version with the correction of this ticket : https://github.com/Galigator/wkhtmltopdf/releases

@Xhilbert
Copy link

Xhilbert commented Mar 2, 2019

Thank you very much !!!!
It works fine !!!

@svenemtell
Copy link

svenemtell commented Nov 12, 2019

Thanks @Galigator, your release made my day!

@ericmillsio
Copy link

ericmillsio commented Jul 16, 2020

A fix for this still hasn't ended up in an official release?

@flexeo
Copy link

flexeo commented Feb 8, 2021

I use wkhtmltox-0.13.0-alpha-7b36694_linux-jessie-amd64 on Debian 8.

Do you have a trick to fix this problem without compile from sources?

Thanks!

@ericmillsio
Copy link

@flexeo #2629 (comment) I can confirm Brenner's comment works as a workaround.

@petegore
Copy link

petegore commented Nov 5, 2021

I still have this issue while croping the html to a 40px square to create a png icon.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests