Code Monkey home page Code Monkey logo

Comments (6)

jcupitt avatar jcupitt commented on June 3, 2024

Hello Christian, PNG is very slow, unfortunately, uncompressed TIFF would be a lot quicker.

Best of all would be simply passing a pointer to large array of uncompressed bytes (this is what pyvips does when interchanging images with numpy and PIL), but that would need additions to php-vips-ext.

Does imagick support creating an image from a memory array?

from php-vips-ext.

kleisauke avatar kleisauke commented on June 3, 2024

Imagick::exportImagePixels / Imagick::importImagePixels and #13 might be relevant here.

from php-vips-ext.

jcupitt avatar jcupitt commented on June 3, 2024

Oh dear Kleis, sorry, I'd forgotten about #13. Let's merge now since we're doing a new version. I'll have a look.

from php-vips-ext.

chregu avatar chregu commented on June 3, 2024

Ah, cool, great. No need to png/tiffsave anymore, will test soon

But regarding tiffsave, I have something I can't explain. Simple case:

$v = \Jcupitt\Vips\Image::newFromFile("animated.gif");
$v = $v->premultiply();
$v = $v->resize(0.5);
$v = $v->unpremultiply();
$v->pngsave("foo.png");
$v->tiffsave("foo.tiff");

The png looks like expected, but the tiff is totally wrong, looks like a black and white image (even without resize). Does it need something more?

Input:

animated

Output (converted to a png outside of vips, since github doesn't support tiff):

foo tiff

from php-vips-ext.

jcupitt avatar jcupitt commented on June 3, 2024

Hello, premultiply / unpremultiply use float format, so you are saving as a float TIFF (12 bytes per pixel). Float TIFF usually uses 0 - 1 for black - white, rather than 0 - 255, so your 0 - 255 float TIFFs look white.

After unpremultiply, I would use cast() to put image image back to the original band format, something like:

$original_format = $image->format;
$image = $image->premultiply()->resize(0.5)->unpremultiply();
$image = $image->cast($original_format);

Processing as float is obviously slower than byte or short, so I would only premultiply if necessary, and cast back as soon as possible after.

from php-vips-ext.

chregu avatar chregu commented on June 3, 2024

Thanks, that works. And with #13 in the works, I think we can close this issue again.

from php-vips-ext.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.