Media Gallery now exposes a small set of APIs that can be used by other Geeklog plugins to manipulate image media. This allows other plugin developers to leverage the work we've done with Media Gallery in supporting three different image backends (ImageMagick, GD Libs and NetPBM).
MG_getMediaMetaData( $filename )
This function will return an array of meta data. This is just a front-end to getID3(). The meta data varies depending on the media type, but the ['mime_type'] element will always be available.
Parameters: |$filename |Full path / filename of the media file |
Returns and arry:
Array of meta data – The contents of the array vary depending on the media type. The ‘mime_type’ element will always be populated.
MG_convertImageFormat ($srcImage, $destImage, $destFormat, $deleteOriginal=1 )
This function will convert an image from one format to another.
Parameters:
| $srcImage | Full path and filename to source image |
| $destImage | Full path and filename to destination image |
| $destFormat | Destination mime type (i.e.; ‘image/png’) |
| $deleteOriginal | If true, delete srcImage after conversion |
Notes:
$srcImage and $destImage can be the same path / filename, this will convert the original image in place.
Returns an array:
| $rc | Return code (true for success, false for failure) |
| $msg | Status Message (only populated when $rc == false) |
MG_resizeImage($srcImage, $destImage, $dImageHeight, $dImageWidth, $mimeType='', $deleteSrc=0 )
This will resize an image to the desired $dImageWidth x $dImageHeight resolution. It will always maintain the original image aspect ratio. For example, if your source image is 640×320 and you pass 200×200 it will actually resize the image to 200×150 to maintain the aspect ratio.
Parameters:
| $srcImage | Full path / filename to src image |
| $destImage | Full path / filename to destination image |
| $dImageHeight | Number of pixels for the target height resolution |
| $dImageWidth | Number of pixels for the target width resolution |
| $mimeType | Src image mime type (optional) |
| $deleteSrc | If true, delete the src image upon successful resizing |
Notes:
The $mimeType field is optional, if not passed (i.e.; blank), MG_resizeImage() will call MG_getMediaMetaData() to determine the source image mime type.
The destination image will be the same mime type as the source image.
Returns an array:
| $rc | Return code (true for success, false for failure) |
| $msg | Status Message (only populated when $rc == false) |
MG_rotateImage( $srcImage, $direction )
This function will rotate an image 'right' or 'left' 90 degrees.
Parameters:
| $srcImage | Full path / filename to image to rotate |
| $direction | Direction to rotate (right or left) |
Returns an array:
| $rc | Return code (true for success, false for failure) |
| $msg | Status Message (only populated when $rc == false) |
MG_watermarkImage( $origImage, $watermarkImage, $opacity, $location )
This function will apply a watermark to the original image.
Parameters:
| $origImage | Full path / filename to image to watermark |
| $watermarkImage | Full path / filename to watermark image. Watermark image must be either JPG or PNG format. |
| $opacity | The percentage of opacity (how dark the watermark image will be) |
| $location | Location to place watermark on the original image: topcenter topright leftmiddle center rightmiddle bottomleft bottomcenter bottomright |
Returns an array:
| $rc | Return code (true for success, false for failure) |
| $msg | Status Message (only populated when $rc == false) |