【发布时间】:2018-06-11 20:45:21
【问题描述】:
我在提交表单之前选择了图片并进行了预览。但我想在选择图像并预览并提交文件后即时编辑文件。
<input type ="file" accept="image/*" id="image" name="image" onchange="preview();">
<p>
<canvas id ="can1" height="0px";></canvas>
</p>
js代码:
<script type="text/javascript">
var img = null;
var canvas1 = document.getElementById("can1");
function preview() {
var inputfile = document.getElementById("image");
img = new SimpleImage(inputfile);
img.drawTo(canvas1);
}
</script>
其实在提交表单后,图像处理在控制器中是这样的:
if ($request->hasFile('image')) {
$filename = time().'-'.$request->image->getClientOriginalName();
$image = Image::make($request->file('image')->getRealPath());
$footer = Image::make(public_path('footer.png'));
$path="photos/shares/uploads/{$filename}";
// Get dimensions for specified images
$width_x=$image->width();
$height_x=$image->height();
$width_y=$footer->width();
// resize the image to a width of $width_x and constrain aspect ratio (auto height)
$footer->resize($width_x,null, function ($constraint) {
$constraint->aspectRatio();
});
$height_y=$footer->height();
$img_canvas = Image::canvas($width_x, $height_x+$height_y);
$img_canvas->insert(Image::make($request->file('image')->getRealPath()));
$img_canvas->insert($footer, 'bottom'); // add offset
$img_canvas->save(public_path($path));
但我希望它在选择图像并显示预览和提交表单后立即发生。
【问题讨论】:
标签: javascript jquery html ajax laravel