WideImage logo

WideImage Wiki : LoadingImages

MainPage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
SourceForge.net Logo

Loading images

Loading an image is easy -- you only have to call the wiImage::load() static method and specify the image source, like this:
$img = wiImage::load(...);


Optionally, you can specify the preferred image format:
$img = wiImage::load('image source', 'png');


This method supports these types of image sources:

From a file

$img = wiImage::load('path/to/image.jpg');

WideImage uses the file extension to load the image properly, but you can specify a format as the second paramter, which can be useful if you don't have an extension in your file (for example: a file that was just uploaded doesn't).
$img = wiImage::load('/path/to/a/file/without/extension', 'gif');


Starting with WideImage 1.0 beta, support for mime-type is added:
$img = wiImage::load('/path/to/a/file/without/extension', 'image/gif');

Format can be a typical image extension (gif, gd, png, jpeg, ...) or a mime-type (image/gif, image/png, image/jpg, image/jpeg, image/pjpeg). GD formats don't have a mime-type.

From a URL

$img = wiImage::load('http://url.of.an/image.gif');

This only works if you have allow_url_fopen enabled in your php.ini.

You can give the image format as the second parameter.

From a string

$image_binary_data = file_get_contents('path/to/image.gif');
// or from a database
$image_binary_data = $row_from_db['image'];
$img = wiImage::load($image_binary_data);


You can give the image format as the second parameter.

From a valid image resource

$image_handle = imagecreatefromjpeg('path/to/a/pic.jpg');
$img = wiImage::load($image_handle);

This could come useful when working with other image libraries or implementing WideImage in your existing code.

When you load an image from a resource, the object takes ownership of the handle. See HandleOwnership for details.

If format is passed as the second parameter, it's ignored.


CategoryDocApi

There are no comments on this page. [Add comment]

WideImage - an Object-Oriented PHP Image Library for Image manipulation
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.2
Page was generated in 0.3907 seconds