Coder Social home page Coder Social logo

sixlabors / imagesharp Goto Github PK

View Code? Open in Web Editor NEW
7.1K 179.0 838.0 118.69 MB

:camera: A modern, cross-platform, 2D Graphics library for .NET

Home Page: https://sixlabors.com/products/imagesharp/

License: Other

C# 99.53% HTML 0.05% JavaScript 0.38% PowerShell 0.05% Batchfile 0.01%
image-processing drawing c-sharp jpeg gif bmp png netcore exif graphics

imagesharp's Introduction

SixLabors.ImageSharp
SixLabors.ImageSharp

Build Status Code coverage License: Six Labors Split Twitter

ImageSharp is a new, fully featured, fully managed, cross-platform, 2D graphics API.

ImageSharp is a new, fully featured, fully managed, cross-platform, 2D graphics library. Designed to simplify image processing, ImageSharp brings you an incredibly powerful yet beautifully simple API.

ImageSharp is designed from the ground up to be flexible and extensible. The library provides API endpoints for common image processing operations and the building blocks to allow for the development of additional operations.

Built against .NET 8, ImageSharp can be used in device, cloud, and embedded/IoT scenarios.

License

Support Six Labors

Support the efforts of the development of the Six Labors projects.

Documentation

  • Detailed documentation for the ImageSharp API is available. This includes additional conceptual documentation to help you get started.
  • Our Samples Repository is also available containing buildable code samples demonstrating common activities.

Questions

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information, see the .NET Foundation Code of Conduct.

Installation

Install stable releases via Nuget; development releases are available via MyGet.

Package Name Release (NuGet) Nightly (Feedz.io)
SixLabors.ImageSharp NuGet feedz.io

Manual build

If you prefer, you can compile ImageSharp yourself (please do and help!)

Alternatively, you can work from command line and/or with a lightweight editor on both Linux/Unix and Windows:

To clone ImageSharp locally, click the "Clone in [YOUR_OS]" button above or run the following git commands:

git clone https://github.com/SixLabors/ImageSharp

Then set the following config to ensure blame commands ignore mass reformatting commits.

git config blame.ignoreRevsFile .git-blame-ignore-revs

If working with Windows please ensure that you have enabled long file paths in git (run as Administrator).

git config --system core.longpaths true

This repository uses Git Large File Storage. Please follow the linked instructions to ensure you have it set up in your environment.

This repository contains Git Submodules. To add the submodules to the project, navigate to the repository root and type:

git submodule update --init --recursive

How can you help?

Please... Spread the word, contribute algorithms, submit performance improvements, unit tests, no input is too little. Make sure to read our Contribution Guide before opening a PR.

Useful tools for development and links to specifications can be found in our wikipage: Useful-tools-and-links.

The ImageSharp Team


JetBrains

Special thanks to JetBrains for supporting us with open-source licenses for their IDEs.

imagesharp's People

Contributors

andy-wilkinson avatar antonfirsov avatar brianpopow avatar cosmo0 avatar dlemstra avatar dmanning23 avatar gfoidl avatar iamcarbon avatar ildarkhayrutdinov avatar jbildstein avatar jeavon avatar jimbobsquarepants avatar jongleur1983 avatar jubilant-enigma avatar luisalfredo92 avatar olivif avatar pekspro avatar poker-sang avatar rytmis avatar sergio0694 avatar simantor avatar simoncropp avatar spacecheetah avatar stefannikolei avatar tbroust-trepia avatar tkp1n avatar tocsoft avatar vpenades avatar woutware avatar ynse01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imagesharp's Issues

Blend modes

It would be great to have the ability to blend colors based on the W3c specification.

http://www.w3.org/TR/compositing-1/#blending

Additional blend modes can be added as static methods on ColorSpacialTransforms in ColorSpacialTransforms.cs

Blend Modes:

  • Separable blend modes
    • normal blend mode
    • multiply blend mode
    • screen blend mode
    • overlay blend mode
    • darken blend mode (committed awaiting review)
    • lighten blend mode (committed awaiting review)
    • color-dodge blend mode
    • color-burn blend mode
    • hard-light blend mode
    • soft-light blend mode
    • difference blend mode
    • exclusion blend mode

Gradient brush

Add support for a 'Gradient brush'

Place to start for anyone wanting to contribute would be to look at the other brush implementations inside the ImageSharp.Drawing project.

I would be nice if this supported both radial and linear gradients probably as 2 different brushes, one for each.

Features wanted;

  • Linear Gradients
  • Radial Gradients
  • Multiple color stops

Common .NET 4.6 Sandbox project for performance profiling

Most of our discussions are happening below separate issue/PR topics now. With the current team activity it seems to be more efficient to me, so I decided to open an issue for this topic, hope it's fine.

I think if we want a performance-aware team, everyone should (must!) be able to profile code. We can't wait for better netcore tooling, we need it now!
It's actually very easy with a classic .NET project referencing ImageSharp as a .NET 4.6 dll. With MSBUILD <Link> it's possible to construct such a project adding just ~5 files!

Why don't have it on the common master branch? :)

Improve unit tests speed

I noticed the unit test suite of the project takes about 4 mins to run, which is pretty slow for unit tests.

Martin Fowler has some recommendations here on unit testing speed, but generally one test should be in the range of milliseconds and the suite in seconds.

We can look into how to speed them up, maybe we can move some expensive initialization. Currently there are 119 tests which run for more than 1s, here's the breakdown.

image

Bad JPG resize quality

I'm having an issue where my original jpg of quality 90 (photoshop thing) is resized it gets a worse quality than if I resize in photoshop.

Is there anyway to improve this or maybe I'm missing to set the quality properly?

NotSupportedException: Image cannot be loaded

I'm using 1.0.0-alpha1-00048, .NET Core 1.1.0. I'm unable to load any images whatsoever. Every single image I try returns this exception:

NotSupportedException: Image cannot be loaded. Available formats:
-ImageSharp.Formats.PngFormat
-ImageSharp.Formats.JpegFormat
-ImageSharp.Formats.GifFormat

I'm manually checking the stream to ensure it's a valid image, and I know they're being handled properly because I ultimately upload to AWS and the files are exact matches. Not sure what's going on. I can provide sample images if you'd like, but it's happening with every one of the 10+ images I tried (random images that happen to be on my computer, all either .jpg, .png, or .gif).

Code:

[HttpPost]
public async Task<IActionResult> Upload(IFormFile image)
{
    var verify = UploadHelpers.VerifyImageUpload(image);
    if (verify != string.Empty)
        return BadRequest(verify.ToGenericErrorJson());

    Image result = null;

    using (var stream = new MemoryStream())
    {
        await image.CopyToAsync(stream);

        UploadHelpers.StripExif(stream);

        result = await _imgSvc.UploadImageAsync(stream, User.Id,
            Path.GetExtension(image.FileName).ToLower(), image.ContentType);
    }

    // do some stuff

    return Ok();
}

public static void StripExif(Stream stream)
{
    // exception thrown here
    var image = new Image(stream);

    // strip Exif tags
}

Improve API design for Codecs

At present we have to pass many options to the codecs as parameters. There is also ambiguity over what exactly "Quality" means - Sometimes it's color count, sometimes compression.

We need to:

  • Create Options classes to pass to the encoders and decoders to reduce parameter count.
  • Remove Quality property from Image<TColor, TPacked>
  • Create overload for Image<TColor, TPacked> that allows passing a specific decoder or decoders with options.

Brushes

From @JimBobSquarePants on December 1, 2015 12:48

This issue wraps several brush types.

I think we should implement at least:

  • Path brush
  • Pattern brush (Not essential but nice to have)
  • Elliptical brush (Not essential but nice to have)
  • Gradient brush (Not essential but nice to have)

I'm envisioning something like :

PathBrush brush = new PathBrush
{
    Color = Color.Black,
    Thickness = 10, // the thickness to draw a line
    Path = vectors // A list of vectors to follow
}

Image.Draw(brush)

The method would draw a Bezier curve following the given path, color, and thickness.

Copied from original issue: JimBobSquarePants/ImageProcessor#264

Interlacing is not supported

From @Bartmax on May 6, 2016 4:25

When using a Png file I get this error:

ImageProcessorCore.ImageFormatException: Interlacing is not supported

some png works but some doesn't.

The code is here:
https://github.com/JimBobSquarePants/ImageProcessor/blob/abbf63f863635d4df1a04d322eccd425db7e82db/src/ImageProcessorCore/Formats/Png/PngDecoderCore.cs#L385

What does this mean? is this a limitation of the library or am I doing something wrong or a bug?

Copied from original issue: JimBobSquarePants/ImageProcessor#379

Issue referencing in .net core

Is this the replacement for ImageProcessor.Core?

I installed this using nuget and it states it is version 0.0.0.0

Before, I would reference it with Using ImageProcessor but this reference doesn't appear to work?

Support for reading writing ICC profiles in Jpeg

Currently we lack support for reading/writing ICC color profiles within Jpeg.

This directly negatively affects the color conversion process that we use for converting YCCK or CMYK jpeg images and prevents us from supporting DCI-P3

Reading in C# should be achievable using code based on Drew Noakes MetaDataExtractor (Apache 2.)

https://github.com/drewnoakes/metadata-extractor-dotnet/blob/5411bd3cad10facfd01deb4b1f6878ee242d98a0/MetadataExtractor/Formats/Icc/IccReader.cs

We'll have to additionally figure out how the conversion process takes place. there's info in WikiPedia but it's limited. @antonfirsov Could you possibly have a dig around libjeg-turbo and see if you can find how it's dealt with there? - My C is poor so I struggle to follow that codebase.

We probably don't need the ability to write a profile, just to store it within the image @dlemstra Perhaps we can work in your plan to store different profiles here?

Please comment below on your thoughts everyone.

No Tiff support.

From @JimBobSquarePants on August 31, 2016 1:49

We should be able to support TIFF

Useful links.

http://partners.adobe.com/public/developer/tiff/index.html

http://www.remotesensing.org/libtiff/

http://www.awaresystems.be/imaging/tiff.html

Current implementation can be found in the tiff-codec branch.

Feature Checklist

  • Reading TIFF file structure
  • Parsing of relevant metadata
  • Extraction of image data blocks
  • Construction of image (from strip data)
  • Construction of image (from tile data)

Compression Types

  • None
  • Ccitt1D
  • PackBits
  • CcittGroup3Fax
  • CcittGroup4Fax
  • Lzw
  • Old Jpeg
  • Jpeg (Technote 2)
  • Deflate (Technote 2)
  • Old Deflate (Technote 2)

Photometric Interpretation Formats

  • WhiteIsZero
  • BlackIsZero
  • Rgb (Chunky)
  • Rgb (Planar)
  • PaletteColor
  • TransparencyMask
  • Separated (TIFF Extension color spaces)
  • YCbCr (TIFF Extension color spaces)
  • CieLab (TIFF Extension color spaces)
  • IccLab (TechNote 1)

Fix StyleCop/compiler warnings

Hey everyone! I've been working on getting rid of our build warnings - stylecop and compiler.

There are 3 categories of warnings left, and I need your help on deciding how to fix those 😄

1. SA1649 - File name must match first type name (4)
This is happening for all classes where we have a generic version and a regular version which share the same name - Brushes, ImageBrush, etc. and we use the convention of {name}`{numberOfTypes}.cs for the file name.
The options I see are:

  • keep the convention and ignore the warning for this specific case
  • get rid of the convention and rename the generic and non generic versions

I would personally like a better distinction between the T and non T versions, and that would also help with the readability of the code.

2. SA1401 - Field must be private (4)

This is happening in JpegDecoderCore only, where we have some internal fields, like below.

        /// <summary>
        /// The byte buffer.
        /// </summary>
        internal Bytes Bytes;

This is a maintainability rule - the best practice is to keep all fields to private, and if anything needs to be exposed it should be done via properties.

Should we change these fields to properties? I'm not very familiar with this code so I'm hoping you will have more reasons for one option or the other.

3. CS0219 - The variable <> is assigned but its value is never used (4)

This is in the test project in ReferenceImplementations. r0 and r4 variables are never used. The fix to remove them is trivial, but I was wondering if them not being used is actually intentional.

some resized images are in the wrong orientation

i've been trying to resize (with cropping) some images to a fixed width of 350 and height of 150 with the following code.

using (var output = new FileStream("output.jpg", FileMode.Create))
{
    Image image = new Image(file.OpenReadStream()); //file is a IFormFile object

    image.Resize(new ImageSharp.Processing.ResizeOptions()
    {
        Mode = ImageSharp.Processing.ResizeMode.Crop,
        Size = new Size(350, 150)
    }).SaveAsJpeg(output, 90);

}

some of the resulting images are 150 wide and 350 height. which is not the result i'm expecting.

how do i get the resulting image to be 350 wide and 150 height no matter what orientation the source image is in?

using 1.0.0-alpha1-00038 from myget with .net core web api project.

some stats:

1.) source image 640w X 1136h => results in 350w X 150h [correct]
2.) source image 750w X 1334h => results in 350w X 150h [correct]
3.) source image 1334w X 750h => results in 150w X 350h [wrong]
4.) source image 960w X 1280h => results in 150w X 350h [wrong]
5.) source image 2448w X 3264h => results in 150w X 350h [wrong]

what's weird is that if i open one of the [wrong] images above in photoshop and export as jpg, imagesharp manages to produce the correct result.

check this zip file for a sample image that fails. and also the photoshop exported version of the same image which works.

Png's are decoding wrong after 1.0.0-alpha-000061

png's are decoded incorrectly on version v1.0.0-alpha-000062 and higher (including 95)

last know good version is v1.0.0-alpha-000061
so i think something went wrong in this commit 27522da

i think it's the same as #24 but this time it's in the decoder, i only have 1 specific image that gives me the issue. all of my other images decode&encode just fine (on version 95)

tested with output format: png,jpeg,bmp,gif (all give the same issue)
used the same simple console app as in #24 (comment)

please don't forget to sleep this time 😄

original source file:
source-file

single-thread output:
single-thread

multi-thread output:
bad-file

Passing Unmanaged Pointer as Pixels buffer in ImageSharp

Part of Wayland development is that I create a Shared Memory Buffer that is being used between processes and I wanted to eliminate the amount of buffer copying between ImageSharp and Shared Memory Buffer. If implemented, we may actually be able to see a relatively fast User Interface on Linux for C# that is easy to use for everyone.

Can ImageSharp implement a safe api that accepts IntPtr for Argb or other image format pixel buffer? (Width/height/strides can be provided if needed.)

Please and thank you

Add additional color spaces.

From @JimBobSquarePants on December 1, 2015 12:29

More a nice to have than anything but I believe that if we are to do this properly we shouldbe able to convert where possible between different color spaces.

Currently we have the following.

  • Color - Float based, premultiplied alpha, No limit to r, g, b, a values allowing for a fuller color range.
  • BGRA32
  • CIE Lab
  • CIE XYZ
  • CMYK
  • HSV
  • HSL
  • YCbCr

Inspiration could be taken from the following:

http://colormine.org/
https://github.com/scijs/color-space

Copied from original issue: JimBobSquarePants/ImageProcessor#260

Jpeg image not opening properly

I'm currently testing out this library to use in my future web app.

It works great for most images but some jpeg images don't open properly. Please check out the attached image. While I can open it in any program, ImageSharp returns 0 for height and width. (I hope Github does not alter the file in any way when uploading it)

ph8261x1

System.AccessViolationException when cropping some images

Hi I am using this library to crop sections out of a larger image. Thousands of them. Every so often it hits an image I try to crop and I get this error

Unhandled Exception: 
Unhandled Exception: 
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at ImageSharp.Processors.CropProcessor`2.<>c__DisplayClass0_1.<Apply>b__0(Int32 y)
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()
   at System.Threading.Tasks.TaskReplicator.Replica.<>c.<.ctor>b__4_0(Object s)
   at System.Threading.Tasks.Task.Execute()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at ImageSharp.Processors.CropProcessor`2.<>c__DisplayClass0_1.<Apply>b__0(Int32 y)
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()
   at System.Threading.Tasks.TaskReplicator.Replica.<>c.<.ctor>b__4_0(Object s)
   at System.Threading.Tasks.Task.Execute()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at ImageSharp.Processors.CropProcessor`2.<>c__DisplayClass0_1.<Apply>b__0(Int32 y)
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()
   at System.Threading.Tasks.TaskReplicator.Replica.<>c.<.ctor>b__4_0(Object s)
   at System.Threading.Tasks.Task.Execute()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

Based on CropProcessor I assume it is when cropping not when reading the image. My pseudo code is like this

for each image in images // there is > 10,000
    image = new Image(path)
    for each section in sections // from another file I load, basically bounding boxes within the image
        image.Crop(...).Save(newFilePath)

Thanks

Decoding failes with memory stream at EOF

Hi,
decoding from a memory stream fails if the stream position is already at EOF.
In example:

Stream zipStream = ... // get a zipped jpeg
MemoryStream unzippedStream = new MemoryStream();
await zipStream.CopyToAsync(unzippedStream);
Image image = new Image(unzippedStream); 

Code above fails with a NotSupportedException "Image cannot be loaded. Available formats: ..." because Image.Decode() find an empty header (Image{TColor].cs line 447) calling stream.Read() at EOF.

The following works:

Stream zipStream = ... // get a zipped jpeg
MemoryStream unzippedStream = new MemoryStream();
await zipStream.CopyToAsync(unzippedStream); 

unzippedStream.Position = 0;  // add this to reset stream position

Image image = new Image(unzippedStream); 

I think Image constructor should set Stream.Position = 0 when decoding images from streams.

Png's are encoding wrong after 1.0.0-alpha-000047

png's are encoded incorrectly on version v1.0.0-alpha-000053 and higher (including 57)

last know good version is v1.0.0-alpha-000052
so i think something went wrong in this commit f814dc3

k so after version v1.0.0-alpha-000053 the error's get really obvious (weird colored blocks)
but before that some images are still encoded incorrectly (getting chopped off) and smaller resize actions turning into black images

currently checking how far back this starts occuring

Support of 8-bit images

Does Image class support 8-bit grayscale images? I mean read, write and convert from other color depths

Animated Gif encoding broken

I updated from 1.0.0-alpha-000075 to 1.0.0-alpha-000195, and noticed that animated gifs seem to now have issues. I have done tests with a couple of images and see similar problems with both: black square artifacts on some frames of the gif.

I have been reproducing the issue by simply resizing the image

new Image(inStream)
	.Resize(300,0)
	.Save(outStream);

My original test image:
test-original

Resized using 1.0.0-alpha-000195
test-195

Resized using 1.0.0-alpha-000075
test-75

basic thumbnail middleware and benchmarking

From @PromontoryProtean on January 28, 2016 6:40

I've been doing some prototyping on middeware for V3. I decided to keep it simple and build a basic thumbnail middleware. I layered it on top of the file manager web app that I have been porting to asp.net core. My repository is here:
https://github.com/PromontoryProtean/AspnetCoreFileManager

It is a basic file manager app (with some quirks to iron out) that has a tile mode that shows thumbnails for images you can upload. I built text file logging into the middleware to benchmark processing times and log exceptions. I learned a couple of interesting things from doing this. First the performance of resizing pngs is really good. I am seeing resize times generally around half a second. Jpgs have the issues we discussed in the performance thread, and I typically ran into memory errors when there were more than 3 large jpgs in a single directory. But for non-jpgs performance has been very good so far.

I took a very simple approach with generating the thumbnails and I am serving them via a memory stream rather than caching them to disk. I was going to try to build a basic cache, but after looking through V2 I wasn't sure what you had in mind for V3 equivalents for IGraphicsProcessor and IWebGraphicsProcessor. Is the general idea to use the Resampler class and/or IResampler? Or are you planning to introduce a new type of interface? I'm assuming the API is still very much in flux, so I'm just wondering what you have in mind for changes to the web apis.

Anyway, hopefully some of this will be useful for ImageProcessor.Web. I hope to help out more directly once I understand the structure and the new APIs a bit more.

Copied from original issue: JimBobSquarePants/ImageProcessor#312

Rotation output quality isn't very nice

Hi,

It looks like there's no interpolation happening for rotation - can I add that in as a feature request? The quality of images, when rotated by arbitrary degrees, are quite poor.

Thanks,

Add additional Shapes for drawing.

Add support for the following shapes

  • Rectangle/Square
  • Ellipse/Circle
  • Regular 'X' sided shapes

There are 2 path to follow adding these the optimised or unoptimised route;

  • unoptimised : convert the shape to simple linear path/point array and proxy down to the generic Polygon class to handle.
  • optimised : create entirely custom logic for all aspects of IShape and IPath required.

You are required to convert down to a point array anyway for things like ComplexPolygon to work thus its probably worth doing these as 2 passes;

  • First pass : Simplify the higher level polygon down a simple Linear path of control points and proxy the heavy lifting onto Polygon (which is built for arbitrary shaped polygons).
  • Second Pass : Optimise the IShape and IPath methods/properties to avoid Polygon as use shape specific logic that can be calculated more efficiently.

[Core] Skip loading\processing of EXIF\metadata when opening file

From @KLuuKer on August 18, 2016 20:15

Great library!
Also good that you are supporting EXIF data but....

I would like to completely skip the processing of EXIF (and any other non relevant metadata) and also not include it in the final output.
Because I am processing\downscaling\compressing images for use on a public facing website and nobody needs to see the EXIF data anyway.

This question was bound to show up :)

Copied from original issue: JimBobSquarePants/ImageProcessor#458

How to configure my project to download from myget?

Hello,

Could you help me please?

I want to use your package in my project but I don't know how to set my project to download packages from MyGet gallery.

I'm using Visual Studio 2015 but my server is linux so it's necessary my server be able to download your package using "dotnet restore" from the linux.

Thanks in advance.

Difference between resize results between System.Drawing & Imagesharp

Hi I'm using this file as the input:

orgtest

You probably allready are aware of that but with System.Drawing it takes on avg: 300ms and with ImageSharp arround 1300ms. Anyway to speed it up?

I also noticed a considerable difference in the resized image.
Done with System.Drawing with these settings:

                        graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        graphics.CompositingQuality = CompositingQuality.HighQuality;
                        graphics.SmoothingMode = SmoothingMode.HighQuality;
                        graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

This is the result from System.Drawing:
currently

With ImageSharp

var im = new Image(stream);
im.Resize(1300, 866, new BicubicResampler()).Save(targetStream);

It looks like the ImageSharp Resized image contains a bit more green. And the filesize is 64kb bigger then the System.Drawing example. I get comparable results with other samplers.
2017-1-18113134

Am I doing something wrong. Is this as designed?

PS: ImageMagick (Magick.Net or Node.JS) and OpenCV return a result very similar to System.Drawing.

Image broken pixels

I resize image
Origin: https://drive.google.com/file/d/0B7jXXO3qQiaRMmxJeXltdDRfeDg/view?usp=sharing
Resize on window: https://drive.google.com/file/d/0B7jXXO3qQiaRUlZ6cndXODJZdXM/view?usp=sharing
Reseze on centos 7: https://drive.google.com/file/d/0B7jXXO3qQiaRdGV1VVNsaVBrc3M/view?usp=sharing

On window Image not broken pixels but on centos 7 Image broken pixels

I using "Neostore.ImageSharp": "1.0.0"
And here is my code

Image imageOrigin = ImageFromFile(originFile);
            int sourceWidth = imageOrigin.Width;
            int sourceHeight = imageOrigin.Height;
            ResizeMode mode = ResizeMode.Crop;
            if ((width > sourceWidth) || (height > sourceHeight) || width <= 0 || height <= 0)
            {
                float nPercentW = 0;
                float nPercentH = 0;
                if (width > 0 && height > 0)
                {
                    nPercentW = ((float)width / (float)sourceWidth);
                    nPercentH = ((float)height / (float)sourceHeight);
                    if (nPercentW < nPercentH)
                    {
                        height = (int)(sourceHeight * nPercentW);
                    }
                    else
                    {
                        width = (int)(sourceWidth * nPercentH);
                    }
                }
                else if (width <= 0)
                {
                    width = (int)(sourceWidth * nPercentH);
                }
                else if (height <= 0)
                {
                    height = (int)(sourceHeight * nPercentW);
                }
                mode = ResizeMode.Min;

            }

            using (FileStream output = File.OpenWrite(newFile))
            {

                ResizeOptions options = new ResizeOptions()
                {
                    Size = new Size(width, height),
                    Mode = mode
                };
                imageOrigin.Resize(options).Save(output);
            }

I resize to Width = 900 and Height =0
Please help me.
Thank

Port/prune code in Clipper.cs into ComplexPolygon.cs

We want to drop the hard dependency on the Clipper.cs source file so we need to port across the code and try to add any optimisations as we go (use Vector2 instead of IntPoint etc) to prevent the need for copying the data structures around.

food for thought: could LinkedList<Vector2>s be used instead of List<IntPoint> as a fist optimisation?

Progressive jpeg with missing EOI marker throws EOFException

From @gdoron on October 31, 2016 12:57

Hi James @JimBobSquarePants,

This specific image:
image
fails when trying to load it.

Stacktrace:

ImageProcessorCore.Formats.JpegDecoderCore+EOFException: Exception of type 'ImageProcessorCore.Formats.JpegDecoderCore+EOFException' was thrown.
at ImageProcessorCore.Formats.JpegDecoderCore.Fill()
at ImageProcessorCore.Formats.JpegDecoderCore.ReadByte()
at ImageProcessorCore.Formats.JpegDecoderCore.ReadByteStuffedByte()
at ImageProcessorCore.Formats.JpegDecoderCore.EnsureNBits(Int32 n)
at ImageProcessorCore.Formats.JpegDecoderCore.DecodeHuffman(Huffman huffman)
at ImageProcessorCore.Formats.JpegDecoderCore.Refine(Block b, Huffman h, Int32 zigStart, Int32 zigEnd, Int32 delta)
at ImageProcessorCore.Formats.JpegDecoderCore.ProcessStartOfScan(Int32 n)
at ImageProcessorCore.Formats.JpegDecoderCore.Decode[TColor,TPacked](Image2 image, Stream stream, Boolean configOnly) at ImageProcessorCore.Image2.Decode(Stream stream)
at ImageProcessorCore.Image2.Load(Stream stream) at Yooocan.Logic.ImageLogic.Resize(Stream stream, Int32 quality, Nullable1 width, Nullable`1 height)

Any clue?

By the way, checkout this story: https://yooocan.com/Story/329/Having-Wheels-Has-Its-Perks
Amazing people, and you're helping them James!

THANKS A LOT!

Copied from original issue: JimBobSquarePants/ImageProcessor#505

image (png) resize broken

I have image (png) export from powerpoint
When i resize image broken
1
600_0_resize_1
And this is my code

Image imageOrigin = ImageFromFile(originFile);
ResizeMode mode = ResizeMode.Min;
using (FileStream output = File.OpenWrite(newFile))
           {

               ResizeOptions options = new ResizeOptions()
               {
                   Size = new Size(600, 0),
                   Mode = mode,
               };
               imageOrigin.Resize(options).Save(output);
           }

I using last code download from https://codeload.github.com/JimBobSquarePants/ImageSharp/zip/master (01/12/2017)
"version": "1.0.0-alpha1-*"

When i resize image (jpg)
20170101085604

715_0_resize_20170101085604

reduce the contrast of the image

Please help me

none-progressive jpeg with missing EOI marker throws EOFException

I'm on 1.0.0-alpha1-00049, .NET Core 1.1.0. An image I'm testing with (attached) is throwing the below exception when I call var image = new Image(stream);. All other images I've tested work properly, but I'm not sure what's happening with this one.

(In case GitHub altered it, I've uploaded the image here.)

Exception:

EOFException: Exception of type 'ImageSharp.Formats.JpegDecoderCore+EOFException' was thrown.

My code:

[HttpPost]
public async Task<IActionResult> Upload(IFormFile image)
{
    using (var stream = new MemoryStream())
    {
        await image.CopyToAsync(stream);

        // image verification, stream variable is not touched/used

        stream.Seek(0, SeekOrigin.Begin);

        StripExif(stream);

        // do stuff
    }

    return Ok();
}

public static void StripExif(Stream stream)
{
    // exception thrown here
    var image = new Image(stream);
    
    stream.Seek(0, SeekOrigin.Begin);

    if (image.ExifProfile == null)
        return;

    // a ton of these follow
    image.ExifProfile.RemoveValue(ExifTag.GPSLatitude);

    // ...

    image.Save(stream);
    stream.Seek(0, SeekOrigin.Begin);
}

Beginning of stack trace:

ImageSharp.Formats.JpegDecoderCore+EOFException: Exception of type 'ImageSharp.Formats.JpegDecoderCore+EOFException' was thrown.
   at ImageSharp.Formats.JpegDecoderCore.Decode[TColor](Image`1 image, Stream stream, Boolean configOnly)
   at ImageSharp.Formats.JpegDecoder.Decode[TColor](Image`1 image, Stream stream)
   at ImageSharp.Image`1.Decode(Stream stream)
   at ImageSharp.Image`1.Load(Stream stream)
   at [removed].StripExif(Stream stream) in [removed]\UploadHelpers.cs:line 39
   at [removed].ImagesController.<Upload>d__5.MoveNext() in [removed]\ImagesController.cs:line 66

Speed. Hot nasty bad-ass speed!

From @JimBobSquarePants on March 16, 2016 9:44

We've got a pretty good feature set for a V1 release.

Now we need to make it fast.

Things to look at:

  • Reducing array allocation ArrayPool, Slice<T>
  • Unsafe code where applicable
  • Moar SIMD
  • Algorithmic tightening
  • Reduce pixel looping
  • Other things

For benchmarking we can use BenchMarkDotNet now that the prerelease supports CoreFX

i-wanna-go-fast-ricky-bobby

Add your thoughts below.

Copied from original issue: JimBobSquarePants/ImageProcessor#347

Drawing an image on an image

From @Schaussi on September 7, 2016 8:11

Unfortunately, I have not found a way to do this yet.
Does a method like Graphics.DrawImage() exist in ImageProcessorCore?

E.g. it would be great if something like this would work:
using (Graphics g = Graphics.FromImage(_resultImage)) { g.DrawImage(_otherImage, x, y); }
Thank you

Copied from original issue: JimBobSquarePants/ImageProcessor#470

Codecs

From @JimBobSquarePants on August 4, 2016 6:15

This issue serves to collect various issues with the image codecs. Additional issues will be added upon identification.

Png

  • Decoder doesn't decode progressive files #379
  • Encoder does not encode progressive files

Jpeg

  • Decoder does not decode CMYK files #444
  • Encoder does not encode CMYK files
  • Encoder does not encode progressive files

Tiff

  • No Tiff support #464

Copied from original issue: JimBobSquarePants/ImageProcessor#446

Blending & Padding. How to Position a smaller image on a larger canvas using an x,y offset.

I have a background image of lets say 1000 x 600 pixels and a smaller overlay image of 128 x 80 pixels.

the desired outcome
What I need to do is produce an output image by placing the ovelay.jpg on the background.jpg at the x,y coordinates.

what I've tried so far
The following takes the overlay to the middle of the larger background image. I cannot seem to find how to affect the positioning using the x,y offsets.

    using (var backgroundStream = StreamExtentions.GetImageStream("scene_bg.jpg")) {
        var outPath = @"c:\temp\output.jpg";
        using (var output = File.OpenWrite(outPath)) {
            var background = new Image(backgroundStream);
            var overlay = default(Image);
            using (var overlayStream = StreamExtentions.GetImageStream("overlay.png")) {
                overlay = new Image(overlayStream);
            }

            var opacity = 100;
            var x = 0;
            var y = 0;
           
            var result = overlay.Pad(background.Width, background.Height);
            background .Blend(result, opacity)
                                .SaveAsJpeg(output);
        }
    }

Is this possible at the moment?

Split ImageSharp into multiple projects

ImageSharp should be split into multiple projects so you only have to pay for what you need.

  • ImageSharp
    This would contain the Image classes, Colors, Primitives, Bootstrapper, IImageFormat interface, and other core functionality.
  • ImageSharp.Formats.Jpeg
    The jpeg decoder/encoder (registered via Bootstrapper)
  • ImageSharp.Formats.Png
    The png decoder/encoder (registered via Bootstrapper)
  • ImageSharp.Formats.Gif
    The gif decoder/encoder (registered via Bootstrapper)
  • ImageSharp.Formats.Bmp
    The bmp decoder/encoder (registered via Bootstrapper)
  • ImageSharp.Processing
    Contains methods like Resize, Crop, Skew, Rotate - Anything that alters the dimensions of the image.
    Contains methods like Gaussian Blur, Pixelate, Edge Detection - Anything that maintains the original image dimensions.
  • ImageSharp.Metadata
    EXIF, XMP and other classes for editing image metadata.
  • ImageSharp.Drawing
    Brushes and various drawing algorithms.
  • ImageSharp.Drawing.Text
    Various text drawing algorithms.

All packages will live in there own namespaces except the various formats that will share the ImageSharp.Formats namespace.

All extension methods targeting Image<TColor> will live in the global ImageSharp namespace no matter which project they belong to.

All packages to be versioned and release together under a common version number thus if a change happens in ImageSharp.Formats.Gif then ImageSharp.Drawing version number will be bumped so that all packages from a single build will have a single common number. This is likely to not be the case TBC

origin discussion here: https://gitter.im/ImageSharp/General?at=584378420da034021b65da62

This is all open to discussion and this issue is here to permanently capture any decisions made around this.

EDIT: Updated based on feedback.

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.