responsive-loader icon indicating copy to clipboard operation
responsive-loader copied to clipboard

Feature Request - Add support of Image operation for sharp adapter

Open Ngob opened this issue 5 years ago • 5 comments

Hello,

Sharp allowing the possibility of extract an image (a crop) using http://sharp.pixelplumbing.com/en/stable/api-operation/#extract. Does it make sense to add it to this package? With this, it would be nice to be able to chain images transformation, with something like:

              use: [
                   {
                       loader: 'file-loader',
                   }
                   {
                       loader: 'responsive-loader',
                       options: {
                           adapter: require('responsive-loader/sharp-extract'),
                           name: "images/responsive/[name]-[width].[ext]"
                       }
                   },
                   {
                       loader: 'responsive-loader',
                       options: {
                           adapter: require('responsive-loader/sharp')
                       }
                   },
               ],

this way, we can resize then extract the image (looks like another feature request).

Ngob avatar Sep 21 '18 18:09 Ngob

good stuff; want! do we have a pending PR for this?

evdama avatar Dec 06 '18 08:12 evdama

Not sure if it's possible/necessary to chain loaders for this. How about something like

{
  loader: 'responsive-loader',
  options: {
      adapter: require('responsive-loader/sharp'),
      operations: [["rotate", 90], "extract"]
  }
}

// Or even better?
{
  loader: 'responsive-loader',
  options: {
      adapter: require('responsive-loader/sharp'),
      operations: img => img.rotate(90).extract()
  }
}

jstcki avatar Dec 06 '18 15:12 jstcki

That do not work in my case, I need to be able to configure it inline: asset.jpg?size=1200&extract_left=151&extract_top=0&extract_width=1200, except if img contains his own query?

For information, I think you are right, I tried to chain it properly but it did not work, I will retry it asap and open an according PR if it works.

Ngob avatar Dec 06 '18 18:12 Ngob

@Ngob: Does this loader with sharp support cropping currently?

strarsis avatar Apr 06 '19 19:04 strarsis

@strarsis not as it is. I modified code to allow cropping, but it work only with inline queries and you can not crop and resize the same image. I can share the code if you like.

Ngob avatar Apr 26 '19 13:04 Ngob