GithubHelp home page GithubHelp logo

Comments (3)

asturur avatar asturur commented on June 8, 2024

please have a look at the documentation, in particular:
http://fabricjs.com/fabric-filters
and the paragraph about webgl and texture size

from fabric.js.

Muhammad-Shoaib-Official avatar Muhammad-Shoaib-Official commented on June 8, 2024

please have a look at the documentation, in particular: http://fabricjs.com/fabric-filters and the paragraph about webgl and texture size

This doesn't work for me. 
Actually, I'm not facing an issue when I apply filters; it cuts the image width to half of the canvas, but I want filters implemented smoothly without losing the image width. I tried it, but it did not work for me. Here is my code.

// intial image load
const loadImage = () => {
canvas?.clear();
fabric.Image.fromURL(src, function (img) {
img.set({ id: 'main_canvas_image', hasControls: false });
img.set({ scaleX: 1, scaleY: 1 });
img.scaleToWidth(canvas.width);

  if (img.height < canvas.height) {
    img.scaleToHeight(canvas.height);
  }

  canvas.add(img);
  canvas.renderAll();
  loadFilterPreview();
});

handleImageMoving();

};

// filters list with preview
const loadFilterPreview = () => {
const filtersList = [
new fabric.Image.filters.Vibrance({ vibrance: 1 }),
new fabric.Image.filters.Contrast({ contrast: 0.1 }),
new fabric.Image.filters.Brightness({ brightness: 0.1 }),
new fabric.Image.filters.Gamma({ gamma: [1, 2, 2] }),
new fabric.Image.filters.HueRotation({ rotation: 90 }),
new fabric.Image.filters.Brightness({ brightness: 0.5 }),
];

const updatedPreviews = [
  { label: 'Original', preview: '', filters: [] },
  {
    label: 'Studio',
    preview: '',
    filters: [filtersList[0], filtersList[1]],
  },
  { label: 'Spotlight', preview: '', filters: [filtersList[2]] },
  { label: 'Prime', preview: '', filters: [filtersList[3]] },
  { label: 'Classic', preview: '', filters: [filtersList[4]] },
  { label: 'Edge', preview: '', filters: [filtersList[5]] },
  { label: 'Luminate', preview: '', filters: [filtersList[6]] },
];

setFilterPreview(
  updatedPreviews.map(filterItem => ({
    ...filterItem,
    preview: canvas?.toDataURL?.(),
  }))
);

};

// useEffect for handle filter change
useEffect(() => {
const current = filterPreview.find(e => e.label === filter);
if (current && canvas) {
const canvasImage = canvas
?.getObjects()
?.find(e => e.id === 'main_canvas_image');

  canvasImage.filters = current.filters;
  canvasImage.applyFilters();
  canvasImage.scaleToWidth(canvas.width);
  canvas.renderAll();
}

}, [filter]);

from fabric.js.

asturur avatar asturur commented on June 8, 2024

Please add a working reproducible case i can't really work with snippets of code that i have to find a way to run.

from fabric.js.

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.