我正在尝试将裁剪的图像上传到 laravel 中的 public/uploads 文件夹。
我可以将图像路径保存到数据库,但无法将裁剪后的图像保存到 public/uploads 文件夹。
这就是我的代码的样子:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
$slideshow = \\App\\Slideshow :: find ( $id ) ; //This is the path to the image that’s in the database. $pieces = explode ( “/” , $slideshow -> image ) ; $image = $pieces [ 0 ] . “/public/” . $pieces [ 1 ] . “/” . $pieces [ 2 ] ; $new_image = $pieces [ 0 ] . “/public/” . $pieces [ 1 ] . “/” . $pieces [ 2 ] ; $image_quality = ’95’ ; list ( $current_width , $current_height ) = getimagesize ( $new_image ) ; //This is the data that gets send from the blade form //This function is cropping the image if ( $final_image == true ) { $slideshow -> cropped_image = $complete ; Storage :: copy ( $image , $final_image ) ; return redirect ( ) -> back ( ) ; |
在裁剪功能之后,我尝试将裁剪后的图像放入变量中,然后将图像放入 public/uploads 文件夹中。
- 欢迎来到堆栈溢出! :) 我认为这个问题可能有一些答案,而不会对你有所帮助。我相信 Laravel 的 Storage 外观默认将文件存储在 storage/app 目录中。
我真的会推荐使用图像干预包,它在这样的实现中非常方便和干净。
安装请看这里,非常简单。
然后进行裁剪,您可以轻松使用软件包的裁剪功能:
| 1 2 3 4 5 6 7 8 9 10 11 |
<?php
$originalImagePath = ‘//your_image_path’ $croppedImage = Image :: make ( $originalImagePath ) ; |

评论(0)