/** * Return the output path for an image. * * @param $path * @return string */ public function outputPath(Image $image) { $path = $image->getImage(); if ($path instanceof FileInterface) { $path = $path->path(); } /** * If the path is already public * then just use it as it is. */ if (str_contains($path, public_path())) { return str_replace(public_path(), '', $path); } /** * If the path is a file or file path then * put it in /app/{$application}/files/disk/folder/filename.ext */ if (is_string($path) && str_is('*://*', $path)) { $application = $this->application->getReference(); list($disk, $folder, $filename) = explode('/', str_replace('://', '/', $path)); if ($rename = $image->getFilename()) { $filename = $rename; if (strpos($filename, DIRECTORY_SEPARATOR)) { $directory = null; } } return "/app/{$application}/files/{$disk}/{$folder}/{$filename}"; } /** * Get the real path relative to our installation. */ $path = str_replace(base_path(), '', $this->realPath($path)); /** * Build out path parts. */ $filename = basename($path); $directory = ltrim(dirname($path), '/\\') . '/'; $application = $this->application->getReference(); if ($image->getAlterations() || $image->getQuality()) { $filename = md5(var_export([$path, $image->getAlterations()], true) . $image->getQuality()) . '.' . $image->getExtension(); } if ($rename = $image->getFilename()) { $directory = null; $filename = ltrim($rename, '/\\'); } return "/app/{$application}/assets/{$directory}{$filename}"; }