|
|
|
|
|
|
ResizeImage |
ResizeImage (
string |
$field |
string |
$saveAs = null, |
integer |
$maxWidth = null, |
integer |
$maxHeight = null, |
integer |
$quality = null, |
boolean |
$constrainProportions = true |
) |
Arguments:
Name |
Description |
$field |
The name of the uploadfield where the image is uploaded |
$saveAs |
How the new image should be saved. When nothing is given, the original will be overwritten.
If you want to save a copy of the original image, use something like this: "dir/to/save/"
IF you want to save it with another filename, use something like this: "dir/to/save/image"
The file wil now be saved as "image.<ext>", where <ext> is the extension of the file. |
$maxWidth |
The maximum width of the image. If none is given, the default is loaded which is set in the config file with the var FH_DEFAULT_RESIZE_WIDTH. |
$maxHeight |
The maximum height of the image. If none is given, this value will be the same as $maxWidth. |
$quality |
The quality used for the resized image. When no quality is given, 80% is used. |
$constrainProportions |
Keep the proportions when the image is resized? |
Description:
NOTE: If only the MaxWidth is set, the MaxHeight will be set to the same value as MaxWidth!
NOTE: The uploadfield creates the dir if it does not exists. The ResizeImage function does NOT! So make sure that the dir exists where the resized image is put!
Example
<?php
// include the class
include('FH3/class.FormHandler.php');
// get the current dir working in
$curDir = $_SERVER['DOCUMENT_ROOT'] . dirname( $_SERVER['PHP_SELF'] );
// upload config
$config = array(
'path' => $curDir .'/uploads/',
'type' => 'jpg jpeg png gif',
'exists' => 'rename'
);
// create new formhandler object
$form = new FormHandler('myForm');
// uploadfield
$form->uploadField('Image', 'image', $config);
// save the resized image as...
// MAKE SURE THAT THIS DIR EXISTS!
$saveAs = $curDir .'/uploads/thumbs/'.$form->value('image');
// resize the image
$form->resizeImage( 'image', $saveAs, 200 );
// submit button...
$form->submitButton();
// commit after form function
$form->onCorrect('doRun');
// flush the form
$form->flush();
// the commit after form function
function doRun($data)
{
global $curDir;
$dir = $curDir .'/uploads/';
// display the images
echo
"<img src='". $dir . "thumbs/" . $data['image'] . "' border='0' />\n".
"<img src='". $dir . $data['image'] ."' border='0' />\n";
}
?>
|
Preview image
See also: UploadField | MergeImage
Latest change: 21 August 09 / 14:15
Comments
|
|
|
|