Thanks for noticing that the confident robot was wrong. I have some questions.

Your first example works and makes sense to me because the transparent method is called with an allocated color and this causes it to return the index of the transparent color: 0 instead of -1.

You second example works but since the transparent method is not called transparent continues to return -1 which according to the doc means transparency is disabled, so how is it transparent?

The answer from gpt looks like it should work like your first example works: the allocated alpha "color" of 127 (transparent) is passed to the transparent method, but instead of returning 0 or -1 or something else, the transparent method now returns 2130706432 which is... two gigabytes?

#!/usr/bin/perl use strict; use warnings; use GD; # First working example my $image = GD::Image->new(1, 1); my $transparent = $image->colorAllocate(0, 0, 0); warn $image->transparent; $image->transparent($transparent); warn $image->transparent; # Second working example $image = GD::Image->newTrueColor(1, 1); $image->alphaBlending(0); $image->saveAlpha(1); $transparent = $image->colorAllocateAlpha(0, 0, 0, 127); warn $image->transparent; $image->setPixel(0, 0, $transparent); warn $image->transparent; # Broken ChatGPT example $image = GD::Image->newTrueColor(1, 1); $image->alphaBlending(0); $image->saveAlpha(1); $transparent = $image->colorAllocateAlpha(0, 0, 0, 127); warn $image->transparent; $image->transparent($transparent); warn $image->transparent;
Output:
-1 at line 9.
0 at line 11.
-1 at line 18.
-1 at line 20.
-1 at line 27.
2130706432 at line 29.

In reply to Re^2: ChatGPT's solution (was: Re: Create email tracking image) by Anonymous Monk
in thread Create email tracking image by Bod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.