Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use jpg as default file type #178

Merged
merged 2 commits into from
Jan 29, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: use jpg as default file type
  • Loading branch information
ambar committed Jan 7, 2021
commit 550533bd7c427f0c58fd4570cc69f38a403d8798
29 changes: 9 additions & 20 deletions src/methods.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
isFunc,
isPlainObject
isFunc
} from './utils/tools'
import {
draw,
@@ -104,7 +103,8 @@ export default function methods () {
}

self.getCropperImage = (opt, fn) => {
const customOptions = opt
const customOptions = Object.assign({fileType: 'jpg'}, opt)
const callback = isFunc(opt) ? opt : isFunc(fn) ? fn : null

let canvasOptions = {
canvasId: id,
@@ -116,10 +116,7 @@ export default function methods () {

let task = () => Promise.resolve()

if (
isPlainObject(customOptions) &&
customOptions.original
) {
if (customOptions.original) {
// original mode
task = () => {
self.targetCtx.drawImage(
@@ -144,14 +141,7 @@ export default function methods () {

return task()
.then(() => {
if (isPlainObject(customOptions)) {
canvasOptions = Object.assign({}, canvasOptions, customOptions)
}

if (isFunc(customOptions)) {
fn = customOptions
}

Object.assign(canvasOptions, customOptions)
const arg = canvasOptions.componentContext
? [canvasOptions, canvasOptions.componentContext]
: [canvasOptions]
@@ -160,14 +150,13 @@ export default function methods () {
})
.then(res => {
const tempFilePath = res.tempFilePath

return isFunc(fn)
? fn.call(self, tempFilePath, null)
return callback
? callback.call(self, tempFilePath, null)
: tempFilePath
})
.catch((err) => {
if (isFunc(fn)) {
fn.call(self, null, err)
if (callback) {
callback.call(self, null, err)
} else {
throw err
}