Giter Site home page Giter Site logo

Comments (3)

adam-prchlik avatar adam-prchlik commented on May 28, 2024 1

Hi, Rik
I tried that before, without success ... but i've managed to make it work with vue-filepond by passing the filter function like Prop 👍

for future reference to other Vue-grammers i will show pseudo code of the whole setup

<template>
        <file-pond
            :imageEditEditor="doka"
            :server="filepondServerOptions"
            :imageTransformImageFilter="filterTransform"
            .............
        />
</template>
<script lang="ts">
import { Component, Vue, Prop } from "vue-property-decorator";

// Import Doka
import { create as CreateDoka } from "@root/ClientApp/libraries/doka/lib/doka.esm.min";
import "@root/ClientApp/libraries/doka/lib/doka.min.css";

// Filepond
import vueFilePond from "vue-filepond";
import "filepond/dist/filepond.min.css";
import { FilePond } from "filepond";

import FilePondPluginImageTransform from "filepond-plugin-image-transform";
// ... import other plugins ....


// instance of filepond that we will use
const filepondInst: any = vueFilePond(
    FilePondPluginImageTransform,
   // other plugins goes here   
);

@Component({
    components: {
        "file-pond": filepondInst
    }
})
export default class FileUpload extends Vue {

    doka: any = null;

    filepondServerOptions: any = {
        url: <some url here>
        process: {
            ondata: this.uploadEnhance
        }        
    };

    dokaOptions: any = {
        // lot of doka options
    };

    created(): void {
        this.doka = CreateDoka();
        this.doka.setOptions(this.dokaOptions);
    }

    filterTransform(file): Promise<boolean> {
        // no gif mimetype, do transform
        if (!/image\/gif/.test(file.type)) {
            return Promise.resolve(true);
        }

        let p = new Promise<boolean>(resolve => {
            const reader = new FileReader();
            reader.onload = e => {
                let res = this.isGif(reader.result as ArrayBuffer);
                resolve(res);
            };
            reader.readAsArrayBuffer(file);
        });
        return p;
    }

    isGif(data: ArrayBuffer): boolean {
        // some magic here
    }
}

</script>

Thanks for help

from filepond-plugin-image-transform.

rikschennink avatar rikschennink commented on May 28, 2024

Hi, you can use the filter method like this, you need to either ignore all GIFs, so check extension, or you need to inspect the actual file data to determine if it's an animated GIF.

imageTransformImageFilter: file =>
    new Promise((resolve, reject) => {
      console.log(file); // file object
      resolve(true) // true if should transform, false if should leave alone
    })

from filepond-plugin-image-transform.

rikschennink avatar rikschennink commented on May 28, 2024

Thanks for posting the Vue snippet 🙏

from filepond-plugin-image-transform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.