Zebra_Form::_resize PHP Method

_resize() private method

This method will do nothing if the file is not a supported image file.
private _resize ( string $control, string $prefix, integer $width, integer $height, boolean $preserve_aspect_ratio = true, integer $method = ZEBRA_IMAGE_BOXED, boolean $background_color = 'FFFFFF', boolean $enlarge_smaller_images = true, $jpeg_quality = 85 ) : boolean
$control string The file upload control's name @param string $prefix If the resized image is to be saved as a new file and the originally uploaded file needs to be preserved, specify a prefix to be used for the new file. This way, the resized image will have the same name as the original file but prefixed with the given value (i.e. "thumb_"). Specifying an empty string as argument will instruct the script to apply the resizing to the uploaded image and therefore overwriting the originally uploaded file. @param integer $width The width to resize the image to. If set to 0, the width will be automatically adjusted, depending on the value of the height argument so that the image preserves its aspect ratio. If preserve_aspect_ratio is set to TRUE and both this and the height arguments are values greater than 0, the image will be resized to the exact required width and height and the aspect ratio will be preserved (see the description for the method argument below on how can this be done). If preserve_aspect_ratio is set to FALSE, the image will be resized to the required width and the aspect ratio will be ignored. If both width and height are set to 0, a copy of the source image will be created (jpeg_quality will still apply). If either width or height are set to 0, the script will consider the value of the {@link preserve_aspect_ratio} to bet set to TRUE regardless of its actual value! @param integer $height The height to resize the image to. If set to 0, the height will be automatically adjusted, depending on the value of the width argument so that the image preserves its aspect ratio. If preserve_aspect_ratio is set to TRUE and both this and the width arguments are values greater than 0, the image will be resized to the exact required width and height and the aspect ratio will be preserved (see the description for the method argument below on how can this be done). If preserve_aspect_ratio is set to FALSE, the image will be resized to the required height and the aspect ratio will be ignored. If both height and width are set to 0, a copy of the source image will be created (jpeg_quality will still apply). If either height or width are set to 0, the script will consider the value of the {@link preserve_aspect_ratio} to bet set to TRUE regardless of its actual value! @param boolean $preserve_aspect_ratio (Optional) If set to TRUE, the image will be resized to the given width and height and the aspect ratio will be preserved. Set this to FALSE if you want the image forcefully resized to the exact dimensions given by width and height ignoring the aspect ratio Default is TRUE. @param int $method (Optional) Method to use when resizing images to exact width and height while preserving aspect ratio. If the $preserve_aspect_ratio property is set to TRUE and both the width and height arguments are values greater than 0, the image will be resized to the exact given width and height and the aspect ratio will be preserved by using on of the following methods: - ZEBRA_IMAGE_BOXED - the image will be scalled so that it will fit in a box with the given width and height (both width/height will be smaller or equal to the required width/height) and then it will be centered both horizontally and vertically. The blank area will be filled with the color specified by the $background_color argument. (the blank area will be filled only if the image is not transparent!) - ZEBRA_IMAGE_NOT_BOXED - the image will be scalled so that it could fit in a box with the given width and height but will not be enclosed in a box with given width and height. The new width/ height will be both smaller or equal to the required width/height - ZEBRA_IMAGE_CROP_TOPLEFT - ZEBRA_IMAGE_CROP_TOPCENTER - ZEBRA_IMAGE_CROP_TOPRIGHT - ZEBRA_IMAGE_CROP_MIDDLELEFT - ZEBRA_IMAGE_CROP_CENTER - ZEBRA_IMAGE_CROP_MIDDLERIGHT - ZEBRA_IMAGE_CROP_BOTTOMLEFT - ZEBRA_IMAGE_CROP_BOTTOMCENTER - ZEBRA_IMAGE_CROP_BOTTOMRIGHT For the methods involving crop, first the image is scaled so that both its sides are equal or greater than the respective sizes of the bounding box; next, a region of required width and height will be cropped from indicated region of the resulted image. Default is ZEBRA_IMAGE_BOXED @param boolean $background_color (Optional) The hexadecimal color of the blank area (without the #). See the method argument. Default is 'FFFFFF' @param boolean $enlarge_smaller_images (Optional) If set to FALSE, images having both width and height smaller than the required width and height, will be left untouched ({@link jpeg_quality} will still apply). Default is TRUE @param boolean $quality (Optional) Indicates the quality of the output image (better quality means bigger file size). Range is 0 - 100 Available only for JPEG files. Default is 85 @return boolean Returns TRUE on success or FALSE otherwise @access private
$prefix string
$width integer
$height integer
$preserve_aspect_ratio boolean
$method integer
$background_color boolean
$enlarge_smaller_images boolean
return boolean
    private function _resize($control, $prefix, $width, $height, $preserve_aspect_ratio = true, $method = ZEBRA_IMAGE_BOXED, $background_color = 'FFFFFF', $enlarge_smaller_images = true, $jpeg_quality = 85)
    {
        // if
        if (isset($this->file_upload[$control]) && isset($this->file_upload[$control]['imageinfo'])) {
            // if the image transformation class was not already instantiated
            if (!isset($this->Zebra_Image)) {
                // create a new instance of the image transformation class
                $this->Zebra_Image = new Zebra_Image();
            }
            // set the file permissions as per Zebra_Form's settings
            $this->Zebra_Image->chmod_value = $this->file_upload_permissions;
            // set the source file
            $this->Zebra_Image->source_path = $this->file_upload[$control]['path'] . $this->file_upload[$control]['file_name'];
            // set the target file
            $this->Zebra_Image->target_path = $this->file_upload[$control]['path'] . trim($prefix) . $this->file_upload[$control]['file_name'];
            // set whether aspect ratio should be maintained or not
            $this->Zebra_Image->maintain_ratio = $preserve_aspect_ratio;
            // set the quality of the output image (better quality means bigger file size)
            // available only for jpeg files; ignored for other image types
            $this->Zebra_Image->jpeg_quality = $jpeg_quality;
            // should smaller images be enlarged?
            $this->Zebra_Image->enlarge_smaller_images = $enlarge_smaller_images;
            // if there was an error when resizing the image, return false
            if (!$this->Zebra_Image->resize($width, $height, $method, $background_color)) {
                return false;
            }
        }
        // if the script gets this far, it means that everything went as planned and we return true
        return true;
    }