Horde_Pdf_Writer::_parseJPG PHP Method

_parseJPG() protected method

Extract info from a JPEG file.
protected _parseJPG ( string $file ) : array
$file string Filename of JPEG image
return array Assoc. array of info
    protected function _parseJPG($file)
    {
        // Extract info from a JPEG file.
        $img = @getimagesize($file);
        if (!$img) {
            throw new Horde_Pdf_Exception(sprintf('Missing or incorrect image file: %s', $file));
        }
        if ($img[2] != 2) {
            throw new Horde_Pdf_Exception(sprintf('Not a JPEG file: %s', $file));
        }
        if (!isset($img['channels']) || $img['channels'] == 3) {
            $colspace = 'DeviceRGB';
        } elseif ($img['channels'] == 4) {
            $colspace = 'DeviceCMYK';
        } else {
            $colspace = 'DeviceGray';
        }
        $bpc = isset($img['bits']) ? $img['bits'] : 8;
        // Read whole file.
        $f = fopen($file, 'rb');
        $data = fread($f, filesize($file));
        fclose($f);
        return array('w' => $img[0], 'h' => $img[1], 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
    }