Skip to content

Change background color when ResizeMode.Pad #466

Description

@OscarCanek

Description

It's possible to change the background color when resizing image with mode Pad. Now is always black, but I would like to change it to other colors.

Steps to Reproduce

newImage.Mutate(x => x
                     .Resize(new SixLabors.ImageSharp.Processing.ResizeOptions
                     {
                         Size = new SixLabors.Primitives.Size(newWidth, newHieght),
                         Mode = SixLabors.ImageSharp.Processing.ResizeMode.Pad                         
                     })
                     );
  • ImageSharp version: 1.0.0-beta0002
  • Environment (Operating system, version and so on): Windows/Linux
  • .NET Framework version: .net core 2.0

Activity

  1. OscarCanek commented on Feb 15, 2018

    @OscarCanek
    Author

    Solution

    Searching inside the package I found the following extension "BackgroundColor" that meet my needs.

    Example

    newImage.Mutate(x => x
                         .Resize(new SixLabors.ImageSharp.Processing.ResizeOptions
                         {
                             Size = new SixLabors.Primitives.Size(newWidth, newHieght),
                             Mode = SixLabors.ImageSharp.Processing.ResizeMode.Pad                         
                         })
                         .BackgroundColor(new Rgba32(12, 12, 221))
                         );
    
  2. JimBobSquarePants commented on Mar 19, 2018

    @JimBobSquarePants
    Member

    Reopening as the solution can be improved upon.

    We should add a parameter to the explicit Pad method to allow a shortcut to setting the color.

    .Mutate(x => x.Pad(int width, int height, TPixel color))

    .Mutate(x => x.Pad(GraphicsOptions options, int width, int height, TPixel color))

    Resize itself will probably stay the same as we don't want to make ResizeOptions a generic type.

  3. added this to the 1.0.0-rc1 milestone on Mar 21, 2019
  4. JimBobSquarePants commented on May 25, 2019

    @JimBobSquarePants
    Member

    1 year later and I've decided against merging the two methods as it adds internal complexity that I don't think is worth it when you can simply chain commands like above.

  5. JimBobSquarePants commented on May 25, 2019

    @JimBobSquarePants
    Member

    Actually. I'm being an idiot. Gimme 5 minutes.

  6. added a commit that references this issue on May 25, 2019
    d0de176
  7. added a commit that references this issue on May 25, 2019
    32d919e
  8. added a commit that references this issue on Aug 25, 2019
    9773e61
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions