Skip to content
/ rim Public

rim - php library to get image types and size of remote images in optimized way

Notifications You must be signed in to change notification settings

matejb/rim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rim

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

Notes

Delete tests for production environment! Lots of large jpeg files was added inside test folder for testing purposes.

Usage

Quick examples:

$rim = new rim();

// single image
$image_data = $rim->getSingleImageTypeAndSize('http://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' => 'http://domain/path_to_png_image.png',
	'gif_image'	=> 'http://domain/path_to_gif_image.gif',
	'jpg_image' => 'http://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' => 'http://domain/path_to_png_image.png',
						'image_data' => array(
								'type' => 'png',
								'width' => '450',
								'height' => '220'
							),
						'error' => array()
					),
	'gif_image' => 	array(
						'url' => 'http://domain/path_to_gif_image.gif',
						'image_data' => array(
								'type' => 'gif',
								'width' => '110',
								'height' => '110'
							),
						'error' => array()
					),
	'jpg_image' => 	array(
						'url' => 'http://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.

Performance

Fetching image types and sizes on Hot New Releases in Books page on amazon.com

Time taken to fetch images

Known issues

  1. If remote server is not accepting Range whole images will be downloaded and performance will drop. Multithreaded capabilities will give same performance benefits.

About

rim - php library to get image types and size of remote images in optimized way

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published