Remote Image Library for PHP is tool to get image types and size of remote images in optimized way.
In PHP common way of getting remote image size is using getimagesize function. Function getimagesize is painfully slow because first whole image needs to be downloaded and that takes time and bandwidth.
For every image rim fetches only few bytes need to determine her type and size also library uses multi thread curl compatibilities so images data are fetched in parallel!
Supported image types are: JPEG, GIF, PNG
Licensed under the GNU Lesser General Public Licence version 3
Delete tests for production environment! Lots of large jpeg files was added inside test folder for testing purposes.
Quick examples:
$rim = new rim();
// single image
$image_data = $rim->getSingleImageTypeAndSize('https://domain/path_to_png_file.png');
// this will $image_data contain on success
$image_data = array(
'type' => 'png',
'width' => '450',
'height' => '320'
);
// if the function fails, this will $image_data contain
$image_data = array(
'error' => // information about the error. see https://github.com/MatejB/rim/blob/master/source/rim.php#L148
);
// multiple image fetch
$images_data_input = array(
'png_image' => 'https://domain/path_to_png_image.png',
'gif_image' => 'https://domain/path_to_gif_image.gif',
'jpg_image' => 'https://domain/path_to_jpeg_image.jpg'
);
// rim options
$rim_options = array(
'max_num_of_threads' => 3, // how many threads to use, 10 is default
);
$images_data = $rim->getMultiImageTypeAndSize($images_data_input, $rim_options);
// this will $images_data contain
$images_data = array(
'png_image' => array(
'url' => 'https://domain/path_to_png_image.png',
'image_data' => array(
'type' => 'png',
'width' => '450',
'height' => '220'
),
'error' => array()
),
'gif_image' => array(
'url' => 'https://domain/path_to_gif_image.gif',
'image_data' => array(
'type' => 'gif',
'width' => '110',
'height' => '110'
),
'error' => array()
),
'jpg_image' => array(
'url' => 'https://domain/path_to_jpeg_image.jpg',
'image_data' => array(
'type' => 'png',
'width' => '250',
'height' => '120'
),
'error' => array()
)
);
See examples and tests for detailed usage examples.
Fetching image types and sizes on Hot New Releases in Books page on amazon.com
- If remote server is not accepting
Range
whole images will be downloaded and performance will drop. Multithreaded capabilities will give same performance benefits.