【问题标题】:AngularJs - Reducing Image Size while saving in databaseAngularJs - 减少图像大小,同时保存在数据库中
【发布时间】:2018-04-18 07:30:18
【问题描述】:

在我的 Angular 应用程序中,我具有浏览和上传图像功能。 Windows7 提供的示例图像(Chrysanthemum.jpg、Desert.jpg 等),大小大于 500KB。我需要存储最大大小为 170KB 的图像(客户端要求)。那么如何在上传到数据库的同时减小图像的大小而不影响太多的图像质量)另外我不希望验证限制用户选择大小大于 170KB 的图像。我正在将图像转换为 Base64 并存储为 SQL Server 的图像数据类型。

我的 HTML 代码:

<input id="BrowseFile" type="file" ngf-select ng-model="vm.picFile" name="file" ngf-change="vm.uploadPic(vm.picFile)" accept="image/*" required >

我的控制器代码:

 this.uploadPic = function (picFile) {
        if (picFile == null)
            console.log("Please select image");
        else {                
                vm.fileName = picFile.name;

                picFile.upload = Upload.base64DataUrl(picFile).then(function (imgBase64) {                         
                    vm.image = imgBase64;   // Storing Uploaded photo string for storing in database.                            
                });
            }
 }

我们将不胜感激任何建议。

注意:我用过 ng-文件上传 图像浏览和上传功能的指令。

更新 1:

我在这个 GitHub 链接上获得了 Angular Image Compress 指令 https://github.com/oukan/angular-image-compress 现在正在使用我现有的代码来压缩图像。

【问题讨论】:

    标签: javascript angularjs image ng-file-upload ng-image-compress


    【解决方案1】:

    angular-image-compress.js 提供了完成这项任务的好方法。

    我已经使用该指令成功实现了图像压缩功能。请参考https://github.com/oukan/angular-image-compress 作为起点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-01
      • 1970-01-01
      • 2011-04-01
      • 2019-12-23
      • 2021-03-16
      • 2018-11-19
      • 2018-01-31
      • 1970-01-01
      相关资源
      最近更新 更多