Skip to content

Commit

Permalink
Update helpers.php
Browse files Browse the repository at this point in the history
  • Loading branch information
amir2b authored Jul 31, 2019
1 parent f5b20d6 commit 74356d2
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions files/helpers.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
<?php

if (!function_exists('image_url')) {
if (! function_exists('image_url')) {

/**
* @param string $file
* @param int $width
* @param int $height
* @param bool $is_crop
* @param string $file
* @param int $width
* @param int $height
* @param bool $is_crop
* @return string
*/
function image_url($file, $width = 0, $height = 0, $is_crop = false)
{
$root_path = config('image-fit.root_path', 'files');
$root_path = config('image-fit.root_path', 'files');

$file = trim($file, '/');
if (empty($file)) {
if (!empty(config('image-fit.image_default')))
if (! empty(config('image-fit.image_default'))) {
$file = config('image-fit.image_default');
else
} else {
return url('vendor/image-fit/no-image.jpg');
}
}

$info = pathinfo($file);

if (count($info) == 4) {
if (substr($info['dirname'], 0, 6) == "{$root_path}/")
$file = config('image-fit.prefix') . '/' . substr($info['dirname'], 6) . "/{$info['filename']}";
elseif ($info['dirname'] == $root_path)
$file = config('image-fit.prefix') . "/{$info['filename']}";
else
$file = config('image-fit.prefix') . "/{$info['dirname']}/{$info['filename']}";
if (count($info) === 4 && in_array($info['extension'], ['png', 'jpg', 'jpeg', 'gif'])) {
if (strpos($info['dirname'], "{$root_path}/") === 0) {
$file = config('image-fit.prefix').'/'.substr($info['dirname'], 6)."/{$info['filename']}";
} elseif ($info['dirname'] === $root_path) {
$file = config('image-fit.prefix')."/{$info['filename']}";
} else {
$file = config('image-fit.prefix')."/{$info['dirname']}/{$info['filename']}";
}

return url($file . ($is_crop ? '_' : '-') . "{$width}x{$height}.{$info['extension']}");
return url($file.($is_crop ? '_' : '-')."{$width}x{$height}.{$info['extension']}");
}

return url($file);
}

}

0 comments on commit 74356d2

Please sign in to comment.