php-vips icon indicating copy to clipboard operation
php-vips copied to clipboard

[suggestion] Add writeToB64 or writeToString

Open jarodium opened this issue 5 years ago • 3 comments

Hello

I would like to suggest a method to be available to writeToString or writeToB64 The method would convert to base64 the image or with dataUri on the fly instead of me base64_encode with another call.

Examples:

$buffer = $x->writeToB64(".jpg","uri") //would accept 'uri' or '' for pure base64 output;

//$buffer has this: 'data:image/jpeg;base64,....'
//automagically the mime type is already load 
echo '<img src="'.$buffer.''">';

Currently base64_encode(....->writeToBuffer(".jpg")) works as well but I did not benchmarked it.

jarodium avatar Dec 19 '19 13:12 jarodium

Hello @jarodium, that's a good idea.

libvips 8.9 lets you define custom input and output streams, so you could make one which wrote b64. It's not available from php-vips yet, unfortunately.

Let's tag this as an enhancement.

jcupitt avatar Dec 20 '19 11:12 jcupitt

Hello @jcupitt

Are there news on this enhancement?

Since I don't find any example to make a custom input/output stream with php-vips, I will take this example and use Imagemagick to printout base64 with it

Best regards

jarodium avatar Feb 09 '22 22:02 jarodium

Hi, I've almost finished a rewrite of php-vips to use the new FFI module. It should make it easy to support the target/source API. The code (in progress still) is here:

https://github.com/libvips/php-vips/tree/switch-to-php-ffi

jcupitt avatar Feb 09 '22 22:02 jcupitt

Let's track streaming here: https://github.com/libvips/php-vips/issues/101

jcupitt avatar Oct 11 '22 09:10 jcupitt