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

[question] How to use True Streaming in PHP?

Open andrefelipe opened this issue 4 years ago • 10 comments

Hello @jcupitt hope to find you well.

Could you please guide me how to use True Streaming in PHP?

I read the release notes, but could not figure how to do in PHP, tried looking in the source code but did not go to far.

My use case is a thumbnailing service on S3, source and target images stay on S3.

I already have it working, but do the old way:

  • first I get the S3 object with AWS SDK PHP
  • then use newFromBuffer
  • then do the operations with thumbnail_image
  • then $image->writeToFile (I am storing on disk for now, but the goal is to store on S3)

Could you please share some insights?

Have a good day.

andrefelipe avatar Aug 23 '20 10:08 andrefelipe

Hello, the new streaming stuff hasn’t been added to the PHP binding yet. It’s not hard, just that no ones got around to it.

PRs very welcome, of course.

jcupitt avatar Aug 23 '20 12:08 jcupitt

Thanks, I understand!

andrefelipe avatar Aug 23 '20 19:08 andrefelipe

Let's reopen as a reminder to fix this.

jcupitt avatar Aug 24 '20 02:08 jcupitt

I'm willing to help on this as I really need this feature, but I have zero idea where to start.

mnavarrocarter avatar May 13 '21 11:05 mnavarrocarter

Hello, you need to add the relevant chunks of the libvips API to php-vips-ext, then expose that in a nice way in php-vips.

The ruby version should give a hint as to the libvips API you need to support and the sort of API you could expose in php-vips, though of course you'd need to implement in C and php:

https://github.com/libvips/ruby-vips/blob/master/lib/vips/source.rb https://github.com/libvips/ruby-vips/blob/master/lib/vips/target.rb https://github.com/libvips/ruby-vips/blob/master/lib/vips/image.rb#L425

An alternative would be to get rid of php-vips-ext and redo everything in php-ffi, which might now have enough features to support php-vips.

https://www.php.net/manual/en/book.ffi.php

I think it used to be missing some stuff, I forget exactly what. Getting rid of php-vips-ext would make php-vips much simpler to install and maintain, so there would be other benefits.

jcupitt avatar May 13 '21 12:05 jcupitt

I might give it a go to using FFI.

I understand that I need to map the C headers to functions to do that, and provide the path to the library for my architecture right? Sorry, but my experience in FFI is very limited.

mnavarrocarter avatar May 14 '21 14:05 mnavarrocarter

That's right. You can use the ruby one as a guide, or there's python too:

https://github.com/libvips/pyvips

They both use ffi to wrap libvips.

There are some general notes in the "binding" chapter of the docs:

https://libvips.github.io/libvips/API/current/binding.md.html

jcupitt avatar May 14 '21 15:05 jcupitt

Thank you for all the useful links. Before I send a PR, I would like to play with it and see if I can do it well. I'll create a repo for trying to implement a small subset of the api. Would you be willing to review it and give me some feedback?

mnavarrocarter avatar May 18 '21 08:05 mnavarrocarter

Of course, I'd be delighted.

jcupitt avatar May 18 '21 09:05 jcupitt

I'm just leaving this here for myself. It has some info I would like to come back to.

https://github.com/libvips/libvips/issues/1885

mnavarrocarter avatar May 18 '21 10:05 mnavarrocarter

We have a PR for this feature, so let's close this issue and move discussion there.

jcupitt avatar Jun 29 '23 23:06 jcupitt