GithubHelp home page GithubHelp logo

wushian / thumbnailsharp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mirzaevolution/thumbnailsharp

0.0 0.0 0.0 39 KB

A simple but awesome library to create a flexibel thumbnail from an image for .NET Framework 4.5+

License: MIT License

C# 100.00%

thumbnailsharp's Introduction

ThumbnailSharp

A specialized library to create an image thumbnail from various sources with better result and supports different image formats. A Thumbnail is something that's not very important sometimes, but for softwares/web apps that require a thumbnail to be uploaded to their databases to be used later becomes so vital. And if we just need to create a simple thumbnail, why do we need a big image composition library that holds unnecessary methods for us? Here, we introduce a simple but powerful library for creating a nice thumbnail either from local or internet (supports async/await) that produces better result than Image.GetThumbnailImage Method from System.Drawing.dll. You can consume the result of operation either as an array of bytes or a stream.

Here are some samples:

Original Image (Landscape)

landscape-image

Thumbnail (Jpeg)

size is set to 250

landscape-image-thumbnail

size is set to 450

landscape-image-thumbnail

Original Image (Portrait)

portrait-image

Thumbnail (Jpeg)

size is set to 250

portrait-image-thumbnail

size is set to 450

portrait-image-thumbnail

Original Image (Square/Proportional)

square-image

Thumbnail (Jpeg)

size is set to 250

square-image

How does it work? Simple, you just need to pass thumbnail size (aspect ratio will be reserved), image source, and image format.

Get thumbnail from internet source

byte[] resultBytes = await new ThumbnailCreator().CreateThumbnailBytesAsync(
	thumbnailSize: 250,
    	urlAddress: new Uri("http://www.sample-image.com/image.jpg",UriKind.Absolute),
    	imageFormat: Format.Jpeg
);
// or
Stream resultStream = await new ThumbnailCreator().CreateThumbnailStreamAsync(
	thumbnailSize: 250,
    	urlAddress: new Uri("http://www.sample-image.com/image.png",UriKind.Absolute),
    	imageFormat: Format.Png
);

Get thumbnail from local source

byte[] resultBytes = new ThumbnailCreator().CreateThumbnailBytes(
	thumbnailSize: 300,
    	imageFileLocation: @"C:\images\image.bmp",
    	imageFormat: Format.Bmp
);
//or
Stream resultStream = new ThumbnailCreator().CreateThumbnailStream(
	thumbnailSize: 300,
    	imageFileLocation: @"C:\images\image.bmp",
    	imageFormat: Format.Bmp
);

Get thumbnail from image stream

byte[] resultBytes = new ThumbnailCreator().CreateThumbnailBytes(
	thumbnailSize: 300,
    	imageStream: new FileStream(@"C:\images\image.jpg",FileMode.Open,FileAccess.ReadWrite),
    	imageFormat: Format.Jpeg
);
//or
Stream resultStream = new ThumbnailCreator().CreateThumbnailStream(
	thumbnailSize: 300,
  	imageStream: new FileStream(@"C:\images\image.jpg",FileMode.Open,FileAccess.ReadWrite),
    	imageFormat: Format.Jpeg
);

Get thumbnail from image bytes

byte[] buffer = GetImageBytes(); //this is just fictitious method to get image data in bytes

byte[] resultBytes = new ThumbnailCreator().CreateThumbnailBytes(
	thumbnailSize: 300,
    	imageBytes: buffer,
    	imageFormat: Format.Gif
);
//or
Stream resultStream = new ThumbnailCreator().CreateThumbnailStream(
	thumbnailSize: 300,
    	imageBytes: buffer,
    	imageFormat: Format.Tiff
);

Take a look our softwares that were built using this library:

ThumbnailSharp.Clients


Ready to taste it?

Install from Nuget.Org

Install-Package ThumbnailSharp -Version 1.0.0

Created by: Mirza Ghulam Rasyid

thumbnailsharp's People

Contributors

idigitech avatar mirzaevolution avatar

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.