Giter Club home page Giter Club logo

rim's Introduction

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.

rim's People

Contributors

matejb avatar juanvillegas avatar

Watchers

Zuz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.