Comments (23)
the actual last known good version is 1.0.0-alpha-000047
so the real problem starts on version v1.0.0-alpha-000048
which would be this commit 52cddd3
i have a large batch of images and on version 48 and up some of them are not getting processed all the way
for example it would stop encoding part way trough the image
and images i make into small thumbnails end up getting completely black
from imagesharp.
version 47 png output is definitely fine
version 64 bmp output is fine (but damn they are huge :)
version 64 gifs have such great pallet support
from imagesharp.
Thanks for all that... Yeah bmps are uncompressed, they'll be massive.
The quantizer is pretty good for gifs, I need to optimise it yet though, far too slow.
The encoder it is then. I'll knock up a parallel test and keep at it.
from imagesharp.
had to wait for the package to get pushed :)
so with the butterfly image in the 50 parallel console app test it works fine,
but when i run the entire product page against it i still get some encoding errors
are you aware of ArrayPool.Shared documentation?
It maintains arrays of multiple sizes, and may hand back a larger array than was actually requested, but will never hand back a smaller array than was requested.
from imagesharp.
Sorry, didn't mean to close that.
Yeah, I've read that, if you look I'm only ever reading the bytesPerScanline
value length from each buffer. I was just doing some debugging in parallel experimenting with something else though and sometimes that value wasn't correct.
I can't for the life of me see how that would happen though, all the variables are private instance ones.
It's after 1am here so I won't be able to do anything more tonight I'm afraid. I'll have another look when I'm more fresh.
from imagesharp.
Once more unto the breach, dear friends, once more...
from imagesharp.
Seems to work fine for me
o wait you already did 😄
tested with 1.0.0-alpha-000075
from imagesharp.
@KLuuKer Thanks for all the extra info that was really useful! Turns out I'd moved a line inside the using statement for the deflater stream. 1.0.0-alpha-000062 work fine now for me.
52cddd3#diff-c61aac0b8f9e954e0dae0ff548a8b063R603
from imagesharp.
bad news everyone.... :(
seems it's not completely fixed (although its allot better now)
there is a small amount of images that have the same "it just stop encoding parts" or weird block parts or other encodings issues
i only get some issues for some resolutions tough, so maybe it's not the pngencoder but some other resizing stuff
i will check\try some more stuff later, but i have todo some other stuff first
using (var thisIsMyOutputData = new MemoryStream())
{
// yes its a normal memorystream and not something weird
ImageResizer.Resize(img.Blob, thisIsMyOutputData, true, 300, 300)
}
internal static void Resize(byte[] image, Stream outputStream, bool resize, int newWidth, int newHeight)
{
using (var stream = new MemoryStream(image, false))
{
Image<Color, uint> img = new Image(stream);
{
if (resize && (img.Width > newWidth || img.Height > newHeight))
{
if (img.Width > img.Height)
{
newHeight = (int)(img.Height / (img.Width / (double)newWidth));
}
else
{
newWidth = (int)(img.Width / (img.Height / (double)newHeight));
}
img = img.Resize(newWidth, newHeight, new Lanczos3Resampler(), true);
}
img.ExifProfile = null; // i have no idea what you are talking about....
if (img.Properties != null && img.Properties.Count > 0)
{
img.Properties.Clear();
}
var encoder = new PngEncoder()
{
Quality = int.MaxValue,
CompressionLevel = 9,
};
encoder.Encode(img, outputStream);
}
}
}
from imagesharp.
@KLuuKer Making a small sidestep here... Why are you not setting the ExifProfile to null to remove the profile? I do think I still need to add a RemoveInvalidTags()
and a Clear()
method to the class.
from imagesharp.
@dlemstra wouldn't it be better if it didn't get loaded in the first place? :)
Didn't change anything tough, still have the same issue.
from imagesharp.
the perpetrator in question (this is a jpeg, yes i know i shouldn't turn it into a png but it should still get converted correctly)
even when skipping the resize it is not correct
from imagesharp.
hmmmm, i think all of the images that are encoded incorrectly are jpeg files
from imagesharp.
Odd @KLuuKer... I'm not seeing this in my tests.
Here's the image encoded as a png
And here is it resized as a png using the Lancsoz3 sampler
BTW that whole code could be written in a much more concise manner...
// Resizing with one dimensions will automatically preserve the aspect ratio.
// Png doesn't preserve EXIF data so you don't need to remove it.
new Image(stream)
.Resize(newWidth, 0, new Lanczos3Resampler(), true)
.SaveAsPng(output);
@dlemstra Could you also dl the image and test on your machine? I want to make sure there is nothing odd going on.
from imagesharp.
@JimBobSquarePants even when using your code, i get errors
internal static void Resize(byte[] image, Stream outputStream, bool resize, int newWidth, int newHeight)
{
using (var stream = new MemoryStream(image, false))
{
new Image(stream)
.Resize(newWidth, 0, new Lanczos3Resampler(), true)
.SaveAsPng(outputStream);
}
}
i must admit I'm running this with multiple images simultaneous about 80 different webrequest (our product index page), so this could be a concurrency issue
from imagesharp.
i made sure all image's are the same, and they have all different kinds of encoding issues
image = File.ReadAllBytes("d:\\temp\\resize-me.jpg");
this is what i get when i have muliple encodings running, some are incorrect in different ways, some incorrect in the same way, some are just fine
from imagesharp.
Ah... now that is interesting. Everything here should be threadsafe but maybe it isn't.
And it's definitely fine before the commit at the top of the thread? And only happens when encoding png files?
If so, The only real change I have made to the png encoder is using is an ArrayPool<T>
to reduce allocation but that is supposed to be threadsafe also.
from imagesharp.
we can ignore the resize code, i commented that out and its still wrong, gonna try outputting jpegs
jpges output just fine (with version 64)
from imagesharp.
Ok... Can you do me a huge favour please and also test gif and bitmap. I want to narrow it down to the png encoder.
from imagesharp.
my simple console app i made just now (same issue)
Parallel.For(1, 50, (i) =>
{
var image = File.ReadAllBytes("resize-me.jpg");
using (var outputStream = new FileStream("output\\" + i + ".png", FileMode.Create))
{
using (var stream = new MemoryStream(image, false))
{
new Image(stream)
.SaveAsPng(outputStream);
}
}
});
from imagesharp.
so i tested 47-51 with the code above and they are fine
but on verion 52 (commit bdb53d8) i get this (the top is wrong for all but the last image in the for loop)
from imagesharp.
Give that push a go please. I was able to recreate the issue with a test and fix it. Bonus was a 20% memory usage reduction.
from imagesharp.
Go take your well deserved sleep, you have a great project I'm leeching off.
I just wont update production :)
from imagesharp.
Related Issues (20)
- Error SixLabors.ImageSharp.ImageFormatException: 'Unexpected chunk followed VP8X header' HOT 3
- File (detected as bmp) fails to open, consumes a lot of memory HOT 4
- regression on latest.. 3 vs 2 with GIF HOT 6
- APNG Decoder incorrectly handles frame offsets and dispose previous with blend over HOT 3
- Hard crash (Internal CLR error) with corrupt PNG image HOT 3
- File conversion from jpg to webp changes colors of the image HOT 1
- Malicious hand-crafted PNG can be used to trigger DOS attack HOT 14
- I have encountered a bug with heigh and width of image HOT 4
- Missing Separable Blending Modes? HOT 2
- AccessViolationException when loading corrupt GIF
- Loading image with DecoderOptions { MaxFrames = 1 } loads multiple frames for attached png file
- Rotation of AffineTransform seems to offset the image by 1 pixel HOT 29
- After the jpeg image is loaded, there is a problem with the image color HOT 1
- Issue for load image in table cell in ver. 3.1.4 HOT 1
- Payloads that caused a DOS attack (GIF / JPEG) HOT 5
- Webp encoding produces completely transparent images HOT 5
- PNG to WebP conversion: some files 10x larger than with `cwebp` HOT 3
- PngEncoder ignores FilterMethod HOT 2
- `Fatal error. Internal CLR error` when working with image created by pointer-based overload of `Image.WrapMemory<TPixel>` HOT 1
- Issues Loading JFIF/JPG images from S3 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imagesharp.