Back to MediaHelper class

Method imageResize

public static array
imageResize
(mixed $width, mixed $height, mixed $target)
Calculate the size of a resized image
Parameters
  • int $width Image width
  • int $height Image height
  • int $target Target size
Returns
  • array The new width and height
Since
  • 3.2
Class: MediaHelper
Project: Joomla

Method imageResize - Source code

/**
 * Calculate the size of a resized image
 *
 * @param   integer  $width   Image width
 * @param   integer  $height  Image height
 * @param   integer  $target  Target size
 *
 * @return  array  The new width and height
 *
 * @since   3.2
 */
public static function imageResize($width, $height, $target)
{
    /*
     * Takes the larger size of the width and height and applies the
     * formula accordingly. This is so this script will work
     * dynamically with any size image
     */
    if ($width > $height) {
        $percentage = $target / $width;
    } else {
        $percentage = $target / $height;
    }
    // Gets the new value and applies the percentage, then rounds the value
    $width = round($width * $percentage);
    $height = round($height * $percentage);
    return array($width, $height);
}