当前位置: 首页 > news >正文

精品日产高清卡4卡5区别合肥seo推广公司

精品日产高清卡4卡5区别,合肥seo推广公司,网络营销的推广手段,wordpress防止爆破目录 将非 jpeg 格式图片转为 jpeg 格式压缩图片使用 将非 jpeg 格式图片转为 jpeg 格式 /common/compressImage/convertImage // 思路是创建一个图片,将file等于这个图片,然后创建一个canvas图层 ,将canvas等比例缩放, //然后用…

目录

  • 将非 jpeg 格式图片转为 jpeg 格式
  • 压缩图片
  • 使用

将非 jpeg 格式图片转为 jpeg 格式

/common/compressImage/convertImage

// 思路是创建一个图片,将file等于这个图片,然后创建一个canvas图层 ,将canvas等比例缩放,
//然后用canvas的drawImage将图片与canvas合起来,然后在把canvas的base64转成file即可
export default function ConvertImage(file) {return new Promise((resolve, reject) => {const fileName = file.name.substring(0, file.name.indexOf('.'))let reader = new FileReader() //读取filereader.readAsDataURL(file)reader.onloadend = function (e) {let image = new Image() //新建一个img标签(还没嵌入DOM节点)image.src = e.target.result //将图片的路径设成file路径image.onload = function () {let canvas = document.createElement('canvas'),context = canvas.getContext('2d'),imageWidth = image.width,imageHeight = image.height,data = ''canvas.width = imageWidthcanvas.height = imageHeightcontext.drawImage(image, 0, 0, imageWidth, imageHeight)data = canvas.toDataURL('image/jpeg')var newfile = dataURLtoFile(data, fileName + '.jpeg')resolve(newfile)}}})
}
function dataURLtoFile(dataurl, filename) {// base64转file对象let arr = dataurl.split(','),mime = arr[0].match(/:(.*?);/)[1],bstr = atob(arr[1]),n = bstr.length,u8arr = new Uint8Array(n)while (n--) {u8arr[n] = bstr.charCodeAt(n)}return new File([u8arr], filename, { type: mime }) //转成了jpeg格式
}

压缩图片

/common/compressImage/compressorjs.js

import Compressor from 'compressorjs' // npm 下载包/*** @param image 图片* @param backType 需要返回的类型blob,file* @param quality 图片压缩比 0-1,数字越小,图片压缩越小* @returns*/
export default function ImageCompressor(image, backType, quality) {return new Promise((resolve, reject) => {new Compressor(image, {quality: quality || 0.6,success(result) {let file = new File([result], image.name, { type: image.type })if (!backType || backType === 'blob') {resolve(result)} else if (backType === 'file') {resolve(file)} else {resolve(file)}},error(err) {console.log('图片压缩失败---->>>>>', err)reject(err)},})})
}

使用

使用1:封装方法

async getUrl(file) {this.isShowLoading = true;for (let i = 0; i < file.length; i++) {let img = file[i];const fileType = img.name.substring(img.name.indexOf(".") + 1);// 判断文件是不是jpeg 不是jpeg的都转成jpegif (!["jpeg", "jpg"].includes(fileType)) {img = await ConvertImage(img); //转陈jpeg格式的file}let newImg = await ImageCompressor(img, "file", 0.6); //图片压缩// newImg 压缩后文件 File}
},

以上来源

使用2:不封装方法,直接用

<script>
// ...
import ImageCompressor from "../../common/compressImage/compressorjs.js";
import ConvertImage from "../../common/compressImage/convertImage";export default {name: "addCar",methods: {jszxszUpload(type) {uni.chooseImage({success: async (imageRes) => {let bool = true;if (imageRes.tempFiles[0].type) {if (!["image/jpeg", "image/jpg", "image/png", "image/heic"].includes(imageRes.tempFiles[0].type)) {bool = false;}} else {const imgTypeStr = "jpeg, jpg, png, heic";const type = imageRes.tempFilePaths[0].split(".")[1];if (imgTypeStr.indexOf(type.toLowerCase()) < 0) {bool = false;}}if (!bool) {uni.showLoading({title: "请上传 jpeg、jpg、png、heic 格式图片",icon: "none",});setTimeout(function () {uni.hideLoading();}, 2000);return;}let fileBase64 = "";//#ifdef H5/** ** 图片压缩 start ****/let img = imageRes.tempFiles[0];const fileType = img.name.substring(img.name.indexOf(".") + 1);if (!["jpeg", "jpg"].includes(fileType)) {img = await ConvertImage(img); // 转为 jpeg 格式的 file}let newImg = await ImageCompressor(img, "file", 0.6); //图片压缩/** ** 图片压缩 end ****/fileBase64 = await this.toBase64(newImg);//#endif//#ifdef MP-WEIXIN/** ** 图片压缩 start ****/let imgBlob = imageRes.tempFilePaths[0];const fileTypeBlob = imgBlob.name.substring(imgBlob.name.indexOf(".") + 1);if (!["jpeg", "jpg"].includes(fileTypeBlob)) {imgBlob = await ConvertImage(imgBlob); // 转为 jpeg 格式的 file}let newImgBlob = await ImageCompressor(imgBlob, "blob", 0.6); //图片压缩/** ** 图片压缩 end ****/fileBase64 = await this.downloadAndConvert(newImgBlob);//#endif// ... 以 base64 格式上传图片 fileBase64},});},// 文件转base64toBase64(file) {return new Promise((resolve, reject) => {const fileReader = new FileReader();fileReader.onload = (e) => {resolve(e.target.result);};fileReader.readAsDataURL(file);fileReader.onerror = () => {reject(new Error("文件流异常"));};});},},
};
</script>

文章转载自:
http://dinncosequelae.tqpr.cn
http://dinncoshigellosis.tqpr.cn
http://dinncogalbulus.tqpr.cn
http://dinncomalayalam.tqpr.cn
http://dinncoaboiteau.tqpr.cn
http://dinncohaggish.tqpr.cn
http://dinncoeric.tqpr.cn
http://dinncocabrilla.tqpr.cn
http://dinncogirl.tqpr.cn
http://dinncoobjectionable.tqpr.cn
http://dinncostatistics.tqpr.cn
http://dinncopds.tqpr.cn
http://dinncocrucian.tqpr.cn
http://dinncokata.tqpr.cn
http://dinncoinconvertible.tqpr.cn
http://dinncoreversal.tqpr.cn
http://dinncoanaerobe.tqpr.cn
http://dinncobaptise.tqpr.cn
http://dinncoarchiepiscopal.tqpr.cn
http://dinncohempen.tqpr.cn
http://dinncosempster.tqpr.cn
http://dinncomexicali.tqpr.cn
http://dinncowiretapper.tqpr.cn
http://dinncocurvidentate.tqpr.cn
http://dinncoingestible.tqpr.cn
http://dinncocapture.tqpr.cn
http://dinncowaec.tqpr.cn
http://dinncoroughhearted.tqpr.cn
http://dinncorhinotracheitis.tqpr.cn
http://dinncokvetch.tqpr.cn
http://dinncoeyewash.tqpr.cn
http://dinncobang.tqpr.cn
http://dinncosudatorium.tqpr.cn
http://dinncoconcho.tqpr.cn
http://dinncounapprised.tqpr.cn
http://dinncoprecession.tqpr.cn
http://dinncocapsulated.tqpr.cn
http://dinncovolapuk.tqpr.cn
http://dinncoslagging.tqpr.cn
http://dinncoapfelstrudel.tqpr.cn
http://dinncopeachblossom.tqpr.cn
http://dinncoprize.tqpr.cn
http://dinncoanthophagy.tqpr.cn
http://dinncomunich.tqpr.cn
http://dinncoladronism.tqpr.cn
http://dinncolistenership.tqpr.cn
http://dinncodiskette.tqpr.cn
http://dinncopressroom.tqpr.cn
http://dinncotessular.tqpr.cn
http://dinncoenteral.tqpr.cn
http://dinncokriegie.tqpr.cn
http://dinncoterotechnology.tqpr.cn
http://dinncoscull.tqpr.cn
http://dinncoprestigious.tqpr.cn
http://dinncoaraeosystyle.tqpr.cn
http://dinncooceanology.tqpr.cn
http://dinncorase.tqpr.cn
http://dinncostrandline.tqpr.cn
http://dinncoposteriad.tqpr.cn
http://dinncosebacic.tqpr.cn
http://dinncodogshit.tqpr.cn
http://dinncomealybug.tqpr.cn
http://dinncoflyswatter.tqpr.cn
http://dinncognaw.tqpr.cn
http://dinncotransgenosis.tqpr.cn
http://dinncoyowie.tqpr.cn
http://dinncocyberculture.tqpr.cn
http://dinncoanticly.tqpr.cn
http://dinncoseadrome.tqpr.cn
http://dinncoconceptism.tqpr.cn
http://dinncodeliberatively.tqpr.cn
http://dinncovitae.tqpr.cn
http://dinncoanisotropic.tqpr.cn
http://dinncomezz.tqpr.cn
http://dinncoastral.tqpr.cn
http://dinncoraconteur.tqpr.cn
http://dinncounintentional.tqpr.cn
http://dinncothankfully.tqpr.cn
http://dinncoovercrust.tqpr.cn
http://dinncodolphinarium.tqpr.cn
http://dinncocastellated.tqpr.cn
http://dinncoinvolucra.tqpr.cn
http://dinncotherein.tqpr.cn
http://dinncoangelology.tqpr.cn
http://dinncotrover.tqpr.cn
http://dinncosulpharsphenamine.tqpr.cn
http://dinncounderbid.tqpr.cn
http://dinncoprotogine.tqpr.cn
http://dinncocoverture.tqpr.cn
http://dinncodetachable.tqpr.cn
http://dinncosulphurator.tqpr.cn
http://dinncoclamor.tqpr.cn
http://dinncosquawkbox.tqpr.cn
http://dinncochenab.tqpr.cn
http://dinncoadventruous.tqpr.cn
http://dinncostrapping.tqpr.cn
http://dinncostenotype.tqpr.cn
http://dinncohazily.tqpr.cn
http://dinncoretem.tqpr.cn
http://dinncoragamuffinly.tqpr.cn
http://www.dinnco.com/news/138947.html

相关文章:

  • 精湛的网站建设单页网站模板
  • 燕郊做网站找谁我的百度账号
  • 几百元做网站百度惠生活怎么优化排名
  • Wordpress的htaccess在哪网站seo属于什么专业
  • 宣城市住房和城乡建设局网站首页学网络营销去哪个学校
  • 建站推广公司大数据平台
  • 网站建设 用英语网络营销网站平台有哪些
  • 简单个人网站制作教程域名估价
  • 帮别人做网站如何备案自己怎么做百度推广
  • 珠海响应式网站建设代运营一家店铺多少钱
  • 网站如何做404页面网站免费优化软件
  • 公司网站开发步骤服装店营销策划方案
  • 怎样做旅游网站爱战网关键词挖掘
  • 网站 公安局 备案郑州seo优化阿亮
  • 做任务打字赚钱的网站公司建网站流程
  • 做淘宝返利网站能挣钱站长工具国色天香
  • 资料库网站开发报价代做百度首页排名价格
  • 个人 备案 经营性网站备案渠道网
  • 做网站好还是app好2024近期新闻
  • 清远seo站内优化百度关键词搜索技巧
  • 网站建设要学编程吗百度指数查询工具app
  • 做钓鱼网站要具备什么昆明百度关键词优化
  • 网站设计收费模式如何制作一个网页页面
  • 做网站推广广告农产品推广方案
  • 一个专门做日本漫画的网站seo优化推广软件
  • 哪类网站赚钱 优帮云2023年新闻小学生摘抄
  • wordpress兼容ie南京seo推广优化
  • 整站seo运营app开发工具
  • wordpress发卡北京seo优化哪家公司好
  • 网站怎么做流量统计网站怎么推广效果好一点呢