|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-08-29 16:41 UTC] contact at amb dot tf
Description:
------------
Imagick::readImageFile() should have a third optional parameter $length like in stream_copy_to_stream(), stream_get_contents(), fgets(), etc.
This will enable reading only a portion of a binary file who contains some image in itself.
Test script:
---------------
<?php
$image = [
'offset' => 42,
'size' => 1337,
];
$file = fopen('images.bin', 'rb');
fseek($file, $image['offset']);
$image = new Imagick();
$image->readImageFile($file, null, $image['size']);
$image->writeImage('image.png');
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 01:00:01 2025 UTC |
Although I can see why you might want this - can't you just do the stream copy to stream yourself? With something like $objInputStream = fopen('images.bin', "rb"); $objTempStream = fopen("php://temp", "w+b"); stream_copy_to_stream( $objInputStream, $objTempStream, $maxlength, $offset) ); rewind($objTempStream); rewind($objInputStream); And then open the image with $imagick->readImageFile($objTempStream); The chance of this ever being implemented in the Imagick extension itself is 'low'.I already did like this: <?php $image = [ 'offset' => 42, 'size' => 1337, ]; $file = fopen('images.bin', 'rb'); fseek($file, $image['offset']); $image = new Imagick(); $image->readImageBlob(stream_get_contents($file, $image['size'])); $image->writeImage('image.png'); But as in your code, the content need to be read twice.