Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



PHP QR Code - How t...
 
Share:
Notifications
Clear all

[Solved] PHP QR Code - How to get a transparent background in your QR Code (PNG)

1 Posts
1 Users
0 Reactions
4,998 Views
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

For those who use PHP QR Code to generate realtime QR Code's for each page on their website:

QR Codes get generated with a white background. For PNG's you can actually make them transparent with a minor modification.

Open the file "qrimage.php" and find this code at the end of the file:

            
            $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
            ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
            ImageDestroy($base_image);
            
            return $target_image;
        }
    }

Now we only have to insert this line between the ImageCopyResized and ImageDestroy line:

   ImageColorTransparent($target_image, $col[0]);

So that the code looks like this:

            
            $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
            ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
    ImageColorTransparent($target_image, $col[0]);
            ImageDestroy($base_image);
            
            return $target_image;
        }
    }

Now every PNG QR Code that gets generated will use transparent, instead of white, as a background color.


   
ReplyQuote
Share: