WideImage logo

WideImage Wiki : SavingImages

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

Saving Images

WideImage supports saving images to a file and string. With string output, you can easily capture image data and write it for example to a database.

Saving to a file

Method signature:
wiImage::saveToFile($uri, $format = null[, additional arguments])

This method writes an image to a file. The format is determined from $uri extension and can be overriden with $format. Additional arguments specify values passed to a file mapper that should be used upon saving.

// simple save to a png
$img->saveToFile('/path/to/image.png');

// override format:
// save a quality 40 jpeg to a file without extension
$img->saveToFile('image-file-without-extension', 'jpeg', 40);

// specify additional arguments
// save to jpeg, don't override format, $quality=40
$Img->saveToFile('image.jpg', null, 40);


Retrieving as a string

Method signature:
wiImage::asString($format[, additional parameters]);

// simple retrieve
$data = $img->asString('gif');

// specify additional arguments
// will retrieve a jpeg, $quality=80
$data = $img->asString('jpg', 80);


Format specifics

JPEG and PNG formats support additional parameters. JPEG supports quality and PNG supports compression level and filters. These parameters are easily passed to the methods:
// quality 80 jpeg
$img->saveToFile('image.jpg', null, 80);

// png without compression
$img->saveToFile('image.png', null, 0);

// png with highest compression level but without filters (the default is PNG_ALL_FILTERS)
$img->saveToFile('image.png', null, 9, PNG_NO_FILTER);

Ofcourse, similar usage applies to the wiImage::asString() method.

For details on JPEG quality, see imagejpeg(), and for PNG compression and filters, see imagepng().

Note: don't be confused if you notice that the compression level parameter of imagepng() has been incorrectly named quality in the PHP manual. PNG format has no quality the way JPEG has it (smaller file size ~= uglier image). It's a lossless image format, so no detail is lost (= the quality remains the same) regardless of the compression level.



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.2776 seconds