I have a complex problem I can figure out. A little history… I used to use Bit.ly to generate qr codes. They went down so I went to google for reliability.
Im using Quark to do stuff with the codes but I need to configure them prior to them going to quark. With Bitly, the qr codes were generated percfecty. However when Google generates them, they are in RGB where bitly generated in grayscale which was perfect. I am using perl’s ImageMagick library to make the necessary edit on the image prior to downloading them.
So far this is what I have.. Google generates a link for a qr code which I download. Because it is in RGB, I need grayscale or bitmap so it will be compatible with quark (effectively).
sub ConvertToGrayscale {
my ($imagePath) = @_;
my $OutPath = $imagePath; # $OutPath =~ s/png$/jpg/i;
my $image = Image::Magick->new() or die 'Unable to create new Image Object.';
my $imageReadError = '';
my $imageWriteError = '';
$imageReadError = $image->Read($imagePath); # returns a code if there is an error
if ($imageReadError) {
warn "Error: $imageReadError. Unable to read image path: $imagePath";
} else {
# $image->Scale(geometry => '75');
# $image->Set('png:color-type' => 'Grayscale', 'png:bit-depth' => '8');
# $image->Set(colorspace => 'Gray', magick => 'JPEG', quality => '100');
$imageWriteError = $image->Write($OutPath);
}
if ($imageWriteError) { warn "Error: $imageWriteError. Unable to write image file: $OutPath"; }
}
Now the complex issue is when I simply use the Set function to set some properties on the image such as colorspace => grayscale, it converts the images mode to grayscale, but when I load it into quark it is huge and I am unable to shrink it small enough to use. So a good candidate for this solution is someone who may have experience with both software.
On a side note that may be helpful. If i load the image into photoshop, I can convert the image made to grayscale there and everything is perfect. So it seems like I would want my perl script to mock what photoshop does to the image.
2
Answers
at this moment I am not really able to test it, but my first guess is that ‘Scale’ is making the whole image roughly five-and-half thousand 75² times ‘bigger’ than the original. I am not sure why you would want to scale it with ImageMagick, mostly the receiving application is well capable of scaling to the desired output at printing-time.
Hope that will help, and if not, I will check tomorrow in the morning
Don’t rely on an external service to create your QR Codes. This is a relatively simple objective, and as you experienced with Bit.ly sometimes services go away.
Instead I’d recommend using a cpan module as demonstrated in this question:
how to make QR codes in perl cgi
. The module it recommends is far from the only one available on cpan, so I’d simply suggest that you spend some time trying out a few until you find one that you like.