|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72965 add a length parameter to Imagick::readImageFile()
Submitted: 2016-08-29 16:41 UTC Modified: 2016-12-09 13:15 UTC
From: contact at amb dot tf Assigned:
Status: Wont fix Package: imagick (PECL)
PHP Version: 7.0.10 OS: Arch Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: contact at amb dot tf
New email:
PHP Version: OS:


 [2016-08-29 16:41 UTC] contact at amb dot tf
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:

$image = [
    'offset' => 42,
    'size' => 1337,

$file = fopen('images.bin', 'rb');
fseek($file, $image['offset']);

$image = new Imagick();
$image->readImageFile($file, null, $image['size']);


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-04 16:38 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");


And then open the image with $imagick->readImageFile($objTempStream);

The chance of this ever being implemented in the Imagick extension itself is 'low'.
 [2016-10-05 02:17 UTC] contact at amb dot tf
I already did like this:

$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']));

But as in your code, the content need to be read twice.
 [2016-12-09 13:15 UTC]
-Status: Open +Status: Wont fix
 [2016-12-09 13:15 UTC]
Adding this complexity to the Imagick library does not sound like a good idea, when it's trivial to work around in userland.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Dec 07 10:05:59 2022 UTC