@param string $file The font file

@return TrueType\File|null $file
194853
public static function load($file) {
      if(!file_exists($file)){
          throw new FontNotFoundException($file);
      }

    $header = file_get_contents($file, false, null, null, 4);
    $class  = null;

    switch ($header) {
      case "\x00\x01\x00\x00":
      case "true":
      case "typ1":
        $class = "TrueType\\File";
        break;

      case "OTTO":
        $class = "OpenType\\File";
        break;

      case "wOFF":
        $class = "WOFF\\File";
        break;

      case "ttcf":
        $class = "TrueType\\Collection";
        break;

      // Unknown type or EOT
      default:
        $magicNumber = file_get_contents($file, false, null, 34, 2);

        if ($magicNumber === "LP") {
          $class = "EOT\\File";
        }
    }

    if ($class) {
      $class = "FontLib\\$class";

      /** @var TrueType\File $obj */
      $obj = new $class;
      $obj->load($file);

      return $obj;
    }

    return null;
  }
644719
public function file( $file = null )
	{
		if ( !is_null( $file ) )
		{
			return $this->_file = $file;
		}
		
		return $this->_file;
	}
63624
public function getResourceByFile(File $file) {
        if (isset($this->resources[md5($file->getAbsolutePath())])) {
            return $this->resources[md5($file->getAbsolutePath())];
        } else {
            return null;
        }
    }
243988
public static function fixFilename($file) {
    if (file_exists($file)) {
      return $file;
    }
    else {
      $file = iconv('utf-8', 'cp1252', $file);
      if (file_exists($file)) {
        return $file;
      }
    }
    return null;
  }
1111058
public function loadStyle($file = null)
    {
        // init required vars
        $content = '';

        // Get style file or get default
        if (is_null($file)) {
            $file = __DIR__.'/../public/github.css';
        }

        // check if style file exists
        if ($this->filesystem->exists($file)) {
            $content = $this->filesystem->get($file);
        }

        // Finally return style
        return "<style>{$content}</style>";
    }
277923
public function loadImageDetails($file = null)
    {
        $file = $file ? $file : $this->pathToImage;

        is_readable($file)
            or $this->raiseError('Image file does not exist.');

        $info = list($this->width, $this->height, $this->fileType) = getimagesize($file);
        if (empty($info)) {
            // To support webp
            $this->fileType = false;
            if (function_exists("exif_imagetype")) {
                $this->fileType = exif_imagetype($file);
                if ($this->fileType === false) {
                    if (function_exists("imagecreatefromwebp")) {
                        $webp = imagecreatefromwebp($file);
                        if ($webp !== false) {
                            $this->width  = imagesx($webp);
                            $this->height = imagesy($webp);
                            $this->fileType = IMG_WEBP;
                        }
                    }
                }
            }
        }

        if (!$this->fileType) {
            throw new Exception("Loading image details, the file doesn't seem to be a valid image.");
        }

        if ($this->verbose) {
            $this->log("Loading image details for: {$file}");
            $this->log(" Image width x height (type): {$this->width} x {$this->height} ({$this->fileType}).");
            $this->log(" Image filesize: " . filesize($file) . " bytes.");
            $this->log(" Image mimetype: " . $this->getMimeType());
        }

        return $this;
    }
270095
final public static function getFromFile($file)
    {
        if (!is_readable($file)) {
            throw new FileNotFoundException;
        }

        $fp    = fopen($file, 'r');
        $class = $namespace = $buffer = '';
        $i     = 0;
        while (!$class) {
            if (feof($fp)) {
                break;
            }

            $buffer .= fread($fp, 512);
            $tokens = @token_get_all($buffer);

            if (strpos($buffer, '{') === false) {
                continue;
            }
            $total = count($tokens);
            for (; $i < $total; $i++) {
                if ($tokens[$i][0] === T_NAMESPACE) {
                    for ($j = $i + 1; $j < count($tokens); $j++) {
                        if ($tokens[$j][0] === T_STRING) {
                            $namespace .= '\\' . $tokens[$j][1];
                        } else if ($tokens[$j] === '{' || $tokens[$j] === ';') {
                            break;
                        }
                    }
                } elseif ($tokens[$i][0] === T_CLASS) {
                    for ($j = $i + 1; $j < count($tokens); $j++) {
                        if ($tokens[$j] === '{') {
                            $class = $tokens[$i + 2][1];
                            break;
                        }
                    }
                    break;
                }
            }
        }
        fclose($fp);
        if (!$class) {
            throw new InvalidClassException;
        }
    
        return $namespace . '\\' . $class;
    }
461977
protected function resolve_file_path($file = null)
    {
        if (is_null($file)) {
            $file = $this->args->file;
        }

        if (file_exists($file)) {
            return $file;
        }

        $dirname  = dirname($file);
        $filename = basename($file);
        $relpath  = $dirname ? "/$dirname" : '';
        $path     = getcwd() . "$relpath/$filename";

        /**
         * realpath will return false if path does not exist
         */
        return realpath($path) ?: str_replace('/./', '/', $path);
    }
1283529
public function create(string $file) : ModularParser
    {
        $clone = clone $this;
        $clone->valid = null;
        $clone->file = false;
        $clone->class = null;
        return $clone->setFileToLoad($file);
    }
676589
private function _loadPng($file)
    {
        $pic = imagecreatefrompng($file);
        if ($pic === false) {
            return null;
        }
        // make sure the images can be properly drawn together
        imagealphablending($pic, false);
        imagesavealpha($pic, true);
        return $pic;
    }
547642
protected function prepareSeedClass($file)
    {
        $extension = $file->getExtension();
        if ($extension !== 'php') {
            return null;
        }
        return '\\' . str_replace('.' . $extension, '', $file->getFilename());
    }
558508
protected function getFileFinder($file) {
    return new class($file) implements ClassFinderInterface {

      protected $file;

      public function __construct($file) {
        $this->file = $file;
      }

      public function findFile($class) {
        return $this->file;
      }
    };
  }
270268
private function getTextFont($font)
	{
		// *** Font path (shou
		$fontPath = dirname(__FILE__) . '/' . $this->fontDir;


		// *** The below is/may be needed depending on your version (see ref)
		putenv('GDFONTPATH=' . realpath('.'));

		// *** Check if the passed in font exsits...
		if ($font == null || ! file_exists($font))
		{

			// *** ...If not, default to this font.
			$font = $fontPath . '/arimo.ttf';

			// *** Check our default font exists...
			if ( ! file_exists($font))
			{

				// *** If not, return false
				if ($this->debug)
				{
					throw new Exception('Font not found');
				}
				else
				{
					return false;
				}
			}
		}

		return $font;

	}
728826
public function getOverlayCanvas($file)
    {
        $canvas = new Canvas();
        $canvas->fromFile(Util::getResourcePath('Preset/'.$file));

        return $canvas;
    }
825059
public function webroot($file)
    {
        $request = $this->_View->getRequest();

        $asset = explode('?', $file);
        $asset[1] = isset($asset[1]) ? '?' . $asset[1] : null;
        $webPath = $request->getAttribute('webroot') . $asset[0];
        $file = $asset[0];

        if (!empty($this->_View->getTheme())) {
            $file = trim($file, '/');
            $theme = $this->_inflectThemeName($this->_View->getTheme()) . '/';

            if (DIRECTORY_SEPARATOR === '\\') {
                $file = str_replace('/', '\\', $file);
            }

            if (file_exists(Configure::read('App.wwwRoot') . $theme . $file)) {
                $webPath = $request->getAttribute('webroot') . $theme . $asset[0];
            } else {
                $themePath = Plugin::path($this->_View->getTheme());
                $path = $themePath . 'webroot/' . $file;
                if (file_exists($path)) {
                    $webPath = $request->getAttribute('webroot') . $theme . $asset[0];
                }
            }
        }
        if (strpos($webPath, '//') !== false) {
            return str_replace('//', '/', $webPath . $asset[1]);
        }

        return $webPath . $asset[1];
    }
614417
public static function type(String $file, $element = NULL)
    {
        if( ! is_file($file) )
        {
            return false;
        }

        $return = mime_content_type($file);

        if( $element === NULL )
        {
            return $return;
        }

        return explode('/', $return)[$element] ?? false;
    }
858180
public function build($file = null)
    {
        $prepared = preg_replace_callback('/%.*%/U', function ($m) {
            if ($m[0] === '%phpdoc%') {
                $string = '/**';
                foreach ($this->components as $name => $classes) {
                    $string .= PHP_EOL . ' * @property ' . implode('|', $classes) . ' $' . $name;
                }
                $string .= PHP_EOL . ' */';
                return $string;
            }
            return $m[0];
        }, $this->template);
        if ($file === null) {
            return $prepared;
        }
        return (bool)file_put_contents($file, $prepared);
    }