8000 add exception handle · LaravelResources/laravel-fileapi@6edc729 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6edc729

Browse files
author
FreedomKnight
committed
add exception handle
1 parent ab48e6e commit 6edc729

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

src/FileApi.php

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,36 @@ public function get($filename, $size = null)
5959

6060
public function getWatermark($filename, $watermark)
6161
{
62-
$path = $this->basepath . $filename;
63-
$image_types = array('image/png', 'image/gif', 'image/jpeg', 'image/jpg');
64-
$watermark_image = $this->setTmpImage(base_path($watermark));
65-
$image = $this->setTmpImage(storage_path('app/' . $path));
66-
imagesavealpha($watermark_image, true);
67-
imagesetbrush($image, $watermark_image);
68-
$watermark_pos_x = imagesx($image) - imagesy($watermark_image);
69-
$watermark_pos_y = imagesy($image) - imagesy($watermark_image);
70-
imageline($image, $watermark_pos_x, $watermark_pos_y, $watermark_pos_x, $watermark_pos_y, IMG_COLOR_BRUSHED);
71-
imagesavealpha($image, true);
72-
if (!Storage::exists('images/wtermark')) {
73-
Storage::makeDirectory('images/watermark');
74-
}
75-
imagepng($image, storage_path('app/images/watermark/' . $filename));
62+
$origin_basepath = $this->basepath;
63+
try {
64+
$path = $this->basepath . $filename;
65+
$image_types = array('image/png', 'image/gif', 'image/jpeg', 'image/jpg');
66+
$watermark_image = $this->setTmpImage(base_path($watermark));
67+
$image = $this->setTmpImage(storage_path('app/' . $path));
68+
imagesavealpha($watermark_image, true);
69+
imagesetbrush($image, $watermark_image);
70+
$watermark_pos_x = imagesx($image) - imagesy($watermark_image);
71+
$watermark_pos_y = imagesy($image) - imagesy($watermark_image);
72+
imageline(
73+
$image,
74+
$watermark_pos_x,
75+
$watermark_pos_y,
76+
$watermark_pos_x,
77+
$watermark_pos_y,
78+
IMG_COLOR_BRUSHED
79+
);
80+
imagesavealpha($image, true);
81+
if (!Storage::exists('images/wtermark')) {
82+
Storage::makeDirectory('images/watermark');
83+
}
84+
imagepng($image, storage_path('app/images/watermark/' . $filename));
7685

77-
$this->basepath = 'images/watermark/';
78-
return $this->getResponse($filename);
86+
$this->basepath = 'images/watermark/';
87+
return $this->getResponse($filename);
88+
} catch (\Exception $e) {
89+
$this->basepath = $origin_basepath;
90+
return $this->getResponse($filename);
91+
}
7992
}
8093

8194
public function thumbs($thumb_sizes = array())

0 commit comments

Comments
 (0)
0