Watermark action -- Opacity Value Ignored

Bug #487435 reported by Alejandro Cuervo on 2009-11-24
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Phatch
High
Nadia Alramli

Bug Description

On version 0.2.4-1 using the Watermark action, the opacity value is ignored.
No matter what value is entered from 0 - 100, opacity doesn't change.

Alejandro Cuervo (a-cuervo) wrote :

This is the action list i used

description: updated
Stani (stani) on 2009-12-12
Changed in phatch:
assignee: nobody → Juho Vepsäläinen (bebraw)
milestone: none → 0.2.6
Juho Vepsäläinen (bebraw) wrote :

I ran the action list (with modifs to image/font paths) against the trunk version of Phatch (rev. 1542) on Ubuntu (9.10) and Win7 (64 bit) and could not reproduce the issue.

Alex, Could you please try the same on your system?
Here are some quickie instructions:
1. Get the trunk using "bzr branch lp:phatch". This creates a new directory, "phatch", that contains the code.
2. Go to phatch/phatch. You should see "phatch.py" there.
3. Run Phatch ("python phatch.py").
4. Run your action list and let me know of the results. Perhaps the issue has been fixed already or it occurs on some certain case (ie. combination of image file formats. It could be that watermark opacity fails against certain input image format for instance. Considering this try running the action list against input images having different file format.)

Perhaps some other developer could test the action list as well?

Alejandro Cuervo (a-cuervo) wrote :

Juho.
I ran the actions list again with the newer version provided by Stani at :
https://launchpad.net/~stani/+archive/ppa/+files/phatch_0.2.5-0ubuntu1~9.10~ppa1_all.deb

Issue still persists. Opacity Value is ignored.
I also tried the same "watermark images" and "input images" on patch 0.1.5 from the Ubuntu 9.04 repositories and they work perfectly. So I don't think is an issue with the watermark images I am using or the input images
I am attaching the watermark image file I am using and also the final image where the opacity value is ignored for reference.

Alejandro Cuervo (a-cuervo) wrote :

Output image with opacity value ignored

Stani (stani) wrote :

Alex, please also provide the input image so Juho can reproduce your exact case.

Changed in phatch:
status: New → Incomplete
Alejandro Cuervo (a-cuervo) wrote :

Attaching original Input image

Juho Vepsäläinen (bebraw) wrote :

Using the provided input image made no difference whatsoever. I still cannot reproduce the issue. As mentioned earlier, perhaps someone else would like to try it?

Alejandro Cuervo (a-cuervo) wrote :

Juho, so it worked for you? the opacity was honored and the output image came out ok?
Are you also on linux?
Could this be the an issue with dependencies/outdated libraries in my ubuntu 9.10?

Juho Vepsäläinen (bebraw) wrote :

Yeah. I gave the input image a go with png watermarks as you did in your action list. I tested it both on Win7 and Ubuntu (9.10) with the same results. Considering it worked here on 9.10 it's most likely not a dependency issue (the watermark code depends on PIL (python-imaging package) ).

Could you provide the image you used in the watermark actions? Perhaps it's somehow different than the ones I tried. It might be some special case that's missing.

Alejandro Cuervo (a-cuervo) wrote :

The image I used in the watermark actions is there in the bug attachments.
http://launchpadlibrarian.net/36717534/viplr_logo_Watermark.png

Stani (stani) wrote :

Alex, that is the watermark image, not the input image on which the watermark is applied! For Phatch bug reports we need your input images and the action list, which you provided earlier.

Alejandro Cuervo (a-cuervo) wrote :

Stani, the original input image was also attached earlier in comment #7 to the Bug attachments:

http://launchpadlibrarian.net/36725548/IMG_1711.JPG

Stani (stani) wrote :

Alex, you're right! Sorry for that.

Juho, i can confirm the issue. If you put opacity to 1, the watermark should almost be invisible but it is completely opaque. Juho can you post your output image with the images of Alex?

Changed in phatch:
importance: Undecided → High
status: Incomplete → Confirmed
Juho Vepsäläinen (bebraw) wrote :

I finally managed to reproduce the issue with the watermark image that Alex provided. I tested it on Win7 with the exact same results. I converted the image to jpg (flattened alpha) and that worked as expected.

I suppose it fails somewhere around imtools.reduce_opacity . There's some special case it's missing.

Stani (stani) wrote :

Juho, thanks for researching this! I hope you can provide a fix.

Juho Vepsäläinen (bebraw) wrote :

I noticed that the watermark image mode is set to "P" (point? is there PIL doc for modes?). As a result the alpha channel produced was totally wrong (squeezed horizontally). I managed to bypass/fix the issue with following hack:

def reduce_opacity(im, opacity):
    ...

    if opacity < 0 or opacity > 1:
        return im

    if im.mode == 'P':
        im = im.convert('RGBA')

    alpha = get_alpha(im)
    alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
    put_alpha(im, alpha)
    return im

As the algorithm works just fine with RGBA it seemed most straightforward to handle the conversion in this stage.

Nadia Alramli (nadiana) wrote :

This hack will work. But the issue will happen again with LA mode images. The problem is actually because of a PIL bug. It doesn't handle LA mode properly. We should change get_alpha to use 'RGBA' instead of 'LA'. I didn't have the chance to test this change, but I'm sure it will fix the bug.

=== modified file 'phatch/lib/imtools.py'
--- phatch/lib/imtools.py 2009-10-06 05:47:25 +0000
+++ phatch/lib/imtools.py 2009-12-14 23:15:38 +0000
@@ -507,7 +507,7 @@
     if has_alpha(image):
         return image.split()[-1]
     if image.mode == 'P' and 'transparency' in image.info:
- return image.convert('LA').split()[-1]
+ return image.convert('RGBA').split()[-1]
     # No alpha layer, create one.
     return Image.new('L', image.size, 255)

Stani (stani) on 2010-02-21
Changed in phatch:
milestone: 0.2.6 → 0.2.7
Stani (stani) wrote :

Nadia, do you have a branch for this so I can merge it?

Changed in phatch:
assignee: Juho Vepsäläinen (bebraw) → Nadia Alramli (nadiana)

> Nadia, do you have a branch for this so I can merge it?
>
No it wasn't pushed to any branch. It was just a proposed fix that I didn't
try myself since I was busy, but I'm almost certain it should work.

Stani (stani) wrote :

@Nadia. Ok, make a branch and let me know when it is ready.

Stani (stani) on 2010-02-24
Changed in phatch:
status: Confirmed → In Progress
Nadia Alramli (nadiana) wrote :

This bug turned out to be more serious than I thought. It was a combination of 2 bugs.
1. Watermark images should be converted to a safe mode
2. There was a serious bug in convert_safe_mode. The transparency index was being deleted before converting to RGBA. Which will result in losing the transparency in the result. This should have been discovered long time ago since this function is used everywhere.

I fixed both bugs along with 2 possible bugs in this branch: https://code.launchpad.net/~nadiana/phatch/bug_fix_487435

Stani (stani) on 2010-02-28
Changed in phatch:
status: In Progress → Fix Committed
Stani (stani) on 2010-03-17
Changed in phatch:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers