Instafilter\Image::convert_number PHP Method

convert_number() protected method

Converts percentages, negatives, and other values to absolute integers.
protected convert_number ( string $input, boolean $x = null ) : integer
$input string
$x boolean Determines if the number relates to the x-axis or y-axis.
return integer The converted number, usable with the image being edited.
    protected function convert_number($input, $x = null)
    {
        // Sanitize double negatives
        $input = str_replace('--', '', $input);
        $orig = $input;
        $sizes = $this->sizes();
        $size = $x ? $sizes->width : $sizes->height;
        // Convert percentages to absolutes
        if (substr($input, -1) == '%') {
            $input = floor(substr($input, 0, -1) / 100 * $size);
        }
        // Negatives are based off the bottom right
        if ($x !== null and $input < 0) {
            $input = $size + $input;
        }
        return $input;
    }