php.net |  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:
Package:
Bug Type:
Summary:
From: contact at amb dot tf
New email:
PHP Version: OS:

 

 [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');


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-04 16:38 UTC] danack@php.net
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'.
 [2016-10-05 02:17 UTC] contact at amb dot tf
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.
 [2016-12-09 13:15 UTC] danack@php.net
-Status: Open +Status: Wont fix
 [2016-12-09 13:15 UTC] danack@php.net
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-2018 The PHP Group
All rights reserved.
Last updated: Thu Dec 13 20:01:26 2018 UTC