wallabag / wallabag

wallabag is a self hostable application for saving web pages: Save and classify articles. Read them later. Freely.
https://wallabag.org
MIT License
10.15k stars 757 forks source link

DownloadImage Locally with webp,svg,icon #5328

Open iSwiftLiu opened 3 years ago

iSwiftLiu commented 3 years ago

Hello, is there any plan to support webp, svg these types of pictures stored locally? I tried to modify it according to the code, but because I don’t know PHP, I managed to store the static webp file locally through the imagewebp function, hoping to support svg and webp

Kdecherf commented 3 years ago

Hello,

Do you have example links with webp and svg files?

iSwiftLiu commented 3 years ago

Hello, svg images: https://fuckcloudnative.io/posts/use-wireguard-as-kubernetes-cni/ https://fuckcloudnative.io/posts/egress-tcp/

webp images: https://www.upyun.com/webp?utm_source=zhihu&utm_medium=referral&utm_campaign=26474171&utm_term=webp static: https://p.upyun.com/demo/webp/webp/jpg-0.webp https://p.upyun.com/demo/webp/webp/png-0.webp https://p.upyun.com/demo/webp/webp/gif-0.webp dynamic: https://p.upyun.com/demo/webp/webp/animated-gif-0.webp

my code about static webp:

            case 'webp':
                imagealphablending($im, true);
                imagesavealpha($im, true);
                imagewebp($im, $localPath, 100);
                $this->logger->debug('DownloadImages: Re-creating webp');
                break;

500 internal error appears when storing dynamic webp.

iSwiftLiu commented 3 years ago

It seems that although this error will be reported, the dynamic webp image saved separately has been saved.

500: Internal Server Error
Error: gd-webp cannot allocate temporary buffer
dxarwc3 commented 2 years ago

I had the same issue which also inhibited the mobile app from syncing items. My hack (adapted from a web search result) into Docker image 2.5.1:

wallabag/src/Wallabag/CoreBundle/Helper/DownloadImages.php:~150

// WEBP animations cause E500 with gd-webp and mobile app upload failure.
// Exit here and do not try imagecreate when WEBP animation detected.
if ( $ext == 'webp' && (
   stripos($res->getBody(), 'WEBPVP8X') !== false ||
   stripos($res->getBody(), 'ANIM') !== false )
) {
   return false;
}

(sorry, not enough experience for a PR)

j0k3r commented 2 years ago

Can you share an url so we can reproduce the bug and fix it?

dxarwc3 commented 2 years ago

Thank you for looking into this issue! I believe the offending image is https://dys2p.com/assets/images/tamper-evident-protection/blink.webp (animated), contained in https://dys2p.com/en/2021-12-tamper-evident-protection.html. The URL is the first in a set of items that I added in the Android App and that all got synced together from the app backlog once I added the lines of code shown above.

j0k3r commented 1 year ago

@dxarwc3 sorry for being late to reply.

I didn't get the error but handling animated webp is only supported by PHP >= 8 see https://stackoverflow.com/a/70861406/569101

On what PHP version your wallabag is running?

dxarwc3 commented 1 year ago

@j0k3r: I am using the image from https://hub.docker.com/r/wallabag/wallabag on v2.5.1. Looking into the container, I see PHP 7.4.29.

matejdro commented 1 year ago

Same issue here.

When attempting to export https://blog.galowicz.de/2022/12/28/book-review-algorithms-to-live-by/ as an epub, export will fail with the gd-webp cannot allocate temporary buffer error.

Running Wallabag 2.5.2, also via the official docker image linked above.

9k001 commented 6 months ago

I think the problem has been solved. I used docker to deploy wallabag. You need to pay attention to the choice of mirror image. You can't use lastest directly, be sure to use an image with a version ID. For example: Image: wallabag/wallabag:2.6.8. 2.6.8: it's a mirror version from two months ago. If using: Image: wallabag/wallabag:lastest. Lastest: it's a version from two years ago. This is a common problem in Docker deployment projects, and I overlooked the fact that images such as webp could not be downloaded.

dxarwc3 commented 6 months ago

@9k001: Thank you for the update on this issue. I upgraded Wallabag over the past months using the container image "wallabag/wallabag:VERSION" (currently 2.6.8), but continue to see the same issue. I just reverted my hot-fix above (https://github.com/wallabag/wallabag/issues/5328#issuecomment-1179568077) to plain 2.6.8 and can reproduce the issue with the URL given by @matejdro: https://blog.galowicz.de/2022/12/28/book-review-algorithms-to-live-by/. Trying to save this page from the Firefox Wallabag plugin (still) result in "An error occurred while saving the article", and the log shows:

app1 | 2024/03/09 17:16:39 [error] 59#59: *17 FastCGI sent in stderr: "PHP message: PHP Fatal error: gd-webp cannot allocate temporary buffer in /var/www/wallabag/src/Wallabag/CoreBundle/Helper/DownloadImages.php on line 182" while reading response header from upstream, client: 192.168.xxx.xxx, server: , request: "POST /api/entries.json HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: xxx