-
-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QRGdImage (custom): mime type is not properly set in base64 output #223
Comments
Hola. I've been working with your lib for one of my WP plugins Serbian Addons. With a bit of reorganizing the options object and the output interface, all of the issues can be gone, and you can use only one QRGdImage class for all of the GD needs. If that sounds good to you, I can extrapolate on my suggestion and make a small PoC. If you like it I can make a PR? My universal implementation is here LMK what you think |
Hey, this is basically how it was/is implemented in v5 and earlier but it comes with several downsides such as testing issues and flexibility when extending - also |
I suppose the rework of the options object, and the API is out of the question? 😅 |
@seebeen To be honest, I dislike most of the GD stuff and if it were up to me I'd remove it entirely in favor of ImageMagick and SVG haha. It has a lot of issues because the GD functions only accept integer values, which is one reason why the circular modules look weird on small scale (#23), among other things. The only reason i keep it is because GD is usually pre-installed unlike ImageMagick. So if you have a meaningful proposal for a change that's less horrible than the current v5 or what's in dev-main, feel free to submit a PR. |
I should add:
|
I think more discussion is needed before PR submissions. 😅 If you're open to making this lib work the same, a lot of the inner (and outer) workings can be abstracted and simplified. |
Hmm, i know this library but I don't see how it could solve my particular issue here and i don't want to add more layers of abstraction or more complicated driver detection (which isn't necessary as you choose the driver per output class). What i could do however is to introduce an output class that's based on |
I'll make a simple wrapper around your lib, and make a gist. See if you like it :) |
Semi-related: added basic |
I just tried the example svgWithLogo.php. It would not work unless I added $options->outputType= QROutputInterface::CUSTOM; So could you please indicate, how to handle this, if QROutputInterface shall be gone? |
You were running an example from |
Issue
Currently there is an issue with custom output classes based on
QRGdImage
where the mime type of the base64 output is not properly set to the image type but rather to"custom"
. This happens when a custom output class uses the optional base64 encoding as it is implemented in the methodQRGdImage::dump()
and is invoked via theQROptions
settings:The "imageWithLogo" example is affected by this issue (among others):
php-qrcode/examples/imageWithLogo.php
Lines 66 to 68 in 57448af
The resulting output would not properly display and looks similar to the following:
Further, this issue will always output the image as PNG as this is the
default
in the switch that determines the GD output function.Affected versions
Affected by this issue are all versions of
php-qrcode
since optional base64 encoding was introduced: v3.x, v4.x and the upcoming v5.x.Workaround
There are several workarounds available, one of which is already provided in the above example, that is, manual invocation of the output class and setting
QROptions::$outputType
to the desired output type (setting to "custom" is not necessary in this case and will be ignored):php-qrcode/examples/imageWithLogo.php
Lines 99 to 106 in 57448af
Another workaround could be to hardcode the output or mime type:
Proposed fix
Since this is a low priority issue that can be easily worked around, v3.x and v4.x will not receive any fixes for it. For v5.x i will introduce separate classes for the several
QRGdImage
output types, such asQRGdImagePNG
and so on. In v6, the classQRGdImage
will be made abstract.The base output class
QROutputAbstract
will see the addition of an internal constantMIME_TYPE
that will set the type for the current class and which will be called inQROutputAbstract::toBase64DataURI()
.Further, the setting
QROptions::$outputType
will be deprecated in favor ofQROptions::$outputInterface
, which in turn will also make calling custom classes easier.The text was updated successfully, but these errors were encountered: