skip to Main Content

I get a QRCode png as base64 from a remote service and need to display it on the web. When blowing the picture up without the “vector” data, it blurs:

enter image description here

I write the base64 to disk with

fwrite($ifp, base64_decode($this->getQRCode()));

The resulting png is a bit small (29×29 pixels). When I open it with e.g. Photoshop, I can blow it up without loss so it looks like the “vector” data is intact. Note the “pixels”:

enter image description here

How can I do this on the server side before writing it down to disk and linking to it from the web.

2

Answers


  1. Chosen as BEST ANSWER

    The old school way of blowing up images was to (ideally) double pixels. Smoothing the rough edges that were the result of that process was invented later. So now I go with this:

    imagescale($image, 128, 128, IMG_NEAREST_NEIGHBOUR);
    

  2. You don’t say how you are “blowing the picture up.” Have you tried rescaling the image in PHP?

    $image = imagecreatefrompng($filename);
    $bigimage = imagescale($image, 128, 128, IMG_NEAREST_NEIGHBOUR);
    header("Content-Type: image/png");
    //dumps directly to output
    imagepng($bigimage, null, 0);
    

    Edit: you can try various interpolation modes as specified here, if IMG_NEAREST_NEIGHBOUR isn’t suitable. (Also, note the British/Canadian spelling of neighbour.)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search