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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 04:01:29 2024 UTC