Would it be possible to use the GD PHP library or work with another module to produce text in the margins of a given code?

I am attempting to produce a large number of QR codes for use in a paleontological collection. Each specimen, once entered into the database, would have a physical (printed) QR code placed in its tray to let researchers look it up quickly in the database.

I am using Views to produce a grid of these QR codes with the associated locality and specimen numbers so that they can a) be distinguished once printed and b) remain associated with the specimen if accidents happen (trays dropped, labels lost, etc.). We'll need to print out several hundred thousand of these in the long run if the entire collection is to be covered.

The issue is that when printing from Views (actually producing a PDF that can be printed), even if the locality and specimen fields are within the same grid cell, they sometimes get split up over page breaks. Now I know that's not your problem, and I'm looking for other options, but I think in this case it would be easiest to add the locality and specimen numbers right onto the image.

The question, then, is how to do this. I've put together some PHP that would do what I need, but between Views and Views PHP and Custom Formatters I'm still thinking that the easiest way must be to add this right into the module before the code is displayed. What does everyone think?

// Example from http://php.net/manual/en/function.imagettftext.php

// Load the QR image
$imqr = imagecreatefrompng('code.png');

//Create a larger image
$im = imagecreate(200,200);

//Copy QR into larger image
imagecopy($im, $imqr, 10, 10, 0, 0, 180, 180);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);

// The text to draw
$lnotext = 'Lnumber';
$snotext = 'Snumber';
// Replace path by your own font path
$font = '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf';

// Add some shadow to the text
//imagettftext($im, 20, 0, 11, 21, $black, $font, $text);

// Add the lno text
imagettftext($im, 10, 0, 10, 20, $black, $font, $lnotext);
// Add the sno text
imagettftext($im, 10, 0, 10, 175, $black, $font, $snotext);

// Using imagepng() results in clearer text compared with imagejpeg()
echo "<img src='image.png'>";

Comments

Deciphered’s picture

Status: Active » Patch (to be ported)

Some providers support this, others dont, so for a consistent experience I chose not to do this.

If anything, I would recommend an approach that post-processed the generate image and sent it through one of the existing modules that deals with this sort of thing (Textimage for example).

I don't have time or reason to do this myself, but patches are welcome.

Cheers,
Deciphered.

Deciphered’s picture

Status: Patch (to be ported) » Postponed

Meant to mark as postponed.

Deciphered’s picture

Status: Postponed » Fixed

:Latest version has support for Image styles, and in conjunction with ImageCache Actions you can now add text. May or may not be satisfactory, but I'm marking this as fixed for the moment.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.