I'm looking for a neat way to create a 1x1 transparent PNG to track opening emails. The ways I have been doing it seem overly clumsy.
The code we use in our main CRM reads an image file and outputs it. This is c2012 code and my coding has improved considerably since then!
$file='incl/1x1transparent.png'; print "Content-type: image/png\n"; print "Set-Cookie: abc=xxx; SameSite=none; Max-Age=315576000\n" if $us +er; print "\n"; open IMG, $file; binmode IMG; while (sysread(IMG, $buffer,640)) { print $buffer; } close IMG; exit 0;
I wanted to avoid making an IO call to the filesystem to read in such a small file. My first attempt was to Base64 encode the image and serve that as text but that didn't work...
So I have come up with this solution:
print "Content-type: image/png\n\n"; binmode STDOUT; my $image = GD::Image->new(1, 1); my $white = $image->colorAllocate(255,255,255); $image->transparent($white); print $image->png; exit;
This is better but it seems a bit of overkill to use GD to do this.
Can you suggest a more elegant solution?
In reply to Create email tracking image by Bod
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |