Skip Menu |
 

This queue is for tickets about the Imager CPAN distribution.

Report information
The Basics
Id: 127047
Status: open
Priority: 90/
Queue: Imager

People
Owner: Nobody in particular
Requestors: arthas [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Allow to set white background when removing alpha channel
MIME-Version: 1.0
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
Message-ID: <rt-4.0.18-18400-1536224283-1871.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 625
Download (untitled) / with headers
text/plain 625b
When doing something like this on a transparent PNG: use Imager; use strict; my $img = Imager->new( file => './fsc.png' ); $img = $img->convert( preset => 'noalpha' ); $img = $img->scale( xpixels => 100 ); $img->write( type => 'jpeg', file => './fsc.jpg' ); the background becomes black (curiously, it is white if I don't resize the image). I know I can create a new white image and compose the PNG into it. However, since most of the time what one needs is white background, could maybe an option be added to allow for it i.e.: $img = $img->convert( preset => 'noalpha', background => Imager::Color->new("#FFFFFF") );
CC: ;
MIME-Version: 1.0
X-Spam-Status: No, score=-4.801 tagged_above=-99.9 required=10 tests=[AWL=1.099, BAYES_00=-1.9, FROM_OUR_RT=-4] autolearn=ham
In-Reply-To: <rt-4.0.18-18400-1536224284-1468.127047-4-0 [...] rt.cpan.org>
Content-Disposition: inline
X-Cpan.org: This message routed through the cpan.org mail forwarding service. Please use PAUSE pause.perl.org to configure your delivery settings.
X-Spam-Flag: NO
X-RT-Interface: API
References: <RT-Ticket-127047 [...] rt.cpan.org> <rt-4.0.18-18400-1536224284-1468.127047-4-0 [...] rt.cpan.org>
X-Virus-Scanned: Debian amavisd-new at bestpractical.com
Message-ID: <20180906104435.e2y7oirmit7badlj [...] mars.tony.develop-help.com>
content-type: text/plain; charset="utf-8"
X-RT-Original-Encoding: utf-8
X-Spam-Score: -4.801
Received: from localhost (localhost [127.0.0.1]) by hipster.bestpractical.com (Postfix) with ESMTP id F0666240288 for <cpan-bug+Imager [...] hipster.bestpractical.com>; Thu, 6 Sep 2018 06:44:53 -0400 (EDT)
Received: from hipster.bestpractical.com ([127.0.0.1]) by localhost (hipster.bestpractical.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mwhVyVq11eY5 for <cpan-bug+Imager [...] hipster.bestpractical.com>; Thu, 6 Sep 2018 06:44:52 -0400 (EDT)
Received: from xx1.develooper.com (xx1.develooper.com [207.171.7.115]) by hipster.bestpractical.com (Postfix) with ESMTPS id E21BD24023C for <bug-Imager [...] rt.cpan.org>; Thu, 6 Sep 2018 06:44:51 -0400 (EDT)
Received: from localhost (xx1.develooper.com [127.0.0.1]) by localhost (Postfix) with ESMTP id DAB06122961 for <bug-Imager [...] rt.cpan.org>; Thu, 6 Sep 2018 03:44:48 -0700 (PDT)
Received: from xx1.develooper.com (xx1.develooper.com [127.0.0.1]) by localhost (Postfix) with SMTP id 22EF1122965 for <bug-Imager [...] rt.cpan.org>; Thu, 6 Sep 2018 03:44:46 -0700 (PDT)
Received: from mars.tony.develop-help.com (develop-help.com [14.200.49.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by xx1.develooper.com (Postfix) with ESMTPS id 70B88122961 for <bug-Imager [...] rt.cpan.org>; Thu, 6 Sep 2018 03:44:39 -0700 (PDT)
Received: from mars.tony.develop-help.com (localhost [127.0.0.1]) by mars.tony.develop-help.com (8.15.2/8.15.2/Debian-8) with ESMTP id w86Aia8W006964 for <bug-Imager [...] rt.cpan.org>; Thu, 6 Sep 2018 20:44:36 +1000
Received: (from tony [...] localhost) by mars.tony.develop-help.com (8.15.2/8.15.2/Submit) id w86AiZGv006963 for bug-Imager [...] rt.cpan.org; Thu, 6 Sep 2018 20:44:35 +1000
Delivered-To: cpan-bug+Imager [...] hipster.bestpractical.com
Subject: Re: [rt.cpan.org #127047] Allow to set white background when removing alpha channel
User-Agent: NeoMutt/20170113 (1.7.2)
Return-Path: <tony [...] develop-help.com>
X-Original-To: cpan-bug+Imager [...] hipster.bestpractical.com
X-RT-Mail-Extension: imager
Date: Thu, 6 Sep 2018 20:44:35 +1000
X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' HTML_00_01 0.05, HTML_00_10 0.05, BODYTEXTP_SIZE_3000_LESS 0, BODY_SIZE_2000_2999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, IN_REP_TO 0, LEGITIMATE_SIGNS 0, MSG_THREAD 0, MULTIPLE_REAL_RCPTS 0, NO_URI_HTTPS 0, REFERENCES 0, SPF_NONE 0, __ANY_URI 0, __BOUNCE_CHALLENGE_SUBJ 0, __BOUNCE_NDR_SUBJ_EXEMPT 0, __CD 0, __CP_MEDIA_BODY 0, __CT 0, __CT_TEXT_PLAIN 0, __DQ_NEG_HEUR 0, __DQ_NEG_IP 0, __FORWARDED_MSG 0, __FRAUD_MONEY_CURRENCY 0, __FRAUD_MONEY_CURRENCY_DOLLAR 0, __HAS_CC_HDR 0, __HAS_FROM 0, __HAS_MSGID 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_TEXT_P 0, __MIME_TEXT_P1 0, __MIME_VERSION 0, __NO_HTML_TAG_RAW 0, __REFERENCES 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __SUBJ_ALPHA_NEGATE 0, __SUBJ_REPLY 0, __TO_MALFORMED_2 0, __TO_NAME 0, __TO_NAME_DIFF_FROM_ACC 0, __TO_REAL_NAMES 0, __URI_NO_MAILTO 0, __URI_NO_WWW 0, __URI_NS , __USER_AGENT 0, __zen.spamhaus.org_ERROR '
X-Spam-Level:
X-PMX-Version: 5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2018.9.6.103616
To: Michele Beltrame via RT <bug-Imager [...] rt.cpan.org>
From: Tony Cook <tony [...] develop-help.com>
RT-Message-ID: <rt-4.0.18-12905-1536230695-274.127047-0-0 [...] rt.cpan.org>
Content-Length: 1966
Download (untitled) / with headers
text/plain 1.9k
On Thu, Sep 06, 2018 at 04:58:04AM -0400, Michele Beltrame via RT wrote: Show quoted text
> When doing something like this on a transparent PNG: > > use Imager; > use strict; > > my $img = Imager->new( file => './fsc.png' ); > $img = $img->convert( preset => 'noalpha' ); > $img = $img->scale( xpixels => 100 ); > $img->write( type => 'jpeg', file => './fsc.jpg' ); > > the background becomes black (curiously, it is white if I don't resize the image). > I know I can create a new white image and compose the PNG into it. However, since most of the time what one needs is white background, could maybe an option be added to allow for it i.e.: > > $img = $img->convert( preset => 'noalpha', background => Imager::Color->new("#FFFFFF") );
Thanks for the ticket. If you only need to add the white background because you're saving to JPEG, do you realize you can supply a background colour to write()? $im->write(file => "./fsc.jpg", i_background => Imager::Color->new("#FFF")); The operation you're asking for does seem useful, but it doesn't belong in convert(). The problem with compose() for your case is: - you can just supply a background color, you need to make a new image - you don't get that nice functional flow of out = in->operation() So I expect I'd add: $out = $im->compose_over(color => ...); and maybe later add: $out = $im->compose_over(fill => ...); $out = $im->compose_over(image => ...); and they all return a new image instead of modifying any inputs. Finally, convert(preset => "noalpha") just strips the alpha channel, so a pixel #FF0000 pixel with 25% coverage in the source image with alpha, becomes a full #FF0000 pixel in the output rather than the expected #3f0000 you'd expect against a black background. To demonstrate this, try creating a transparent image in Gimp and use the airbrush to draw on it a little in red. If you save that as a PNG and then use Imager with convert(preset => "noalpha"), you'll see what I mean. Tony
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-12905-1536230695-274.127047-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <RT-Ticket-127047 [...] rt.cpan.org> <rt-4.0.18-18400-1536224284-1468.127047-4-0 [...] rt.cpan.org> <20180906104435.e2y7oirmit7badlj [...] mars.tony.develop-help.com> <rt-4.0.18-12905-1536230695-274.127047-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-9273-1536661274-1486.127047-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 275
Download (untitled) / with headers
text/plain 275b
Hello Tony! Thank you for the detailed reply and explanation. I actually wasn't aware of the i_background write() option, which I see is in the documentation but I overlooked it. Indeed, a compose_over(color => ...) method would me a nice addition. Thanks again, Michele.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.