Giter Club home page Giter Club logo

dynamic-image's Introduction

DynamicImage

Build status

This is the source code repository for DynamicImage, an open source image manipulation library for ASP.NET. DynamicImage helps you simplify the way you deal with images in your ASP.NET websites.

Links

API

DynamicImage allows images to be created in two ways:

  1. Programmatically, using the object model:

     Composition composition = new Composition();
     composition.Layers.Add(new ImageLayer
     {
     	SourceFileName = "~/Assets/Images/AutumnLeaves.jpg",
     	Filters =
     	{
     		new ResizeFilter { Width = Unit.Pixel(800), Mode = ResizeMode.UseWidth }
     	}
     });
     composition.Layers.Add(new TextLayer
     {
     	Text = "Hello World",
     	Filters =
     	{
     		new OuterGlowFilter()
     	}
     });
     string url = ImageUrlGenerator.GetImageUrl(composition);
    
  2. Programmatically, using a fluent interface:

     string imageUrl = new CompositionBuilder()
     	.WithLayer(LayerBuilder.Image.SourceFile("myimage.png")
     		.WithFilter(FilterBuilder.Resize.ToWidth(800))
     	)
     	.WithLayer(LayerBuilder.Text.Text("Hello World")
     		.WithFilter(FilterBuilder.OuterGlow)
     	).Url;
    

Layers

Images in DynamicImage are composed of one or more layers, and each layer can have zero or more filters applied. DynamicImage includes several built-in layer types, and it is straightforward to create your own.

  • Image Layer
  • Fractal Layer (Julia and Mandelbrot)
  • Polygon Shape Layer
  • Rectangle Shape Layer
  • Text Layer

Image Sources

Image Layers accept input from a variety of sources, and it is also straightforward to write your own ImageSource. The image sources included with DynamicImage let you load images from:

  • Raw bytes
  • Binary database field
  • File
  • Remote URL
  • System.Windows.Media.Imaging.BitmapSource object

Filters

Filters are applied to layers to modify them in some way. DynamicImage provides more than 15 filters you can apply to your images, including:

  • Brightness Adjustment
  • Clipping Mask
  • Colour Key
  • Colour Tint
  • Contrast Adjustment
  • Crop
  • Distort Corners
  • Drop Shadow
  • Emboss
  • Feather
  • Gaussian Blur
  • Grayscale
  • Inversion
  • Opacity Adjustment
  • Outer Glow
  • Resize
  • Rotation
  • Sepia
  • Shiny Floor

Caching

Output images can be cached, based on settings in web.config. You can write your own cache provider, and the built-in cache providers are:

  • In-memory
  • XML file

Underpinnings

DynamicImage uses Windows Presentation Foundation (WPF) internally for bitmap manipulation. Most of the filters are written as WPF shader effects, which are compiled into fast SSE instructions, and run with good performance in a server environment.

More information

The DynamicImage website includes a getting started guide, as well as examples of every layer and filter.

If you get stuck, you can try:

Preferably in that order, please :)

Acknowledgements

DynamicImage was created by Sound in Theory Ltd, a web design company based in Exeter, United Kingdom.
Sound in Theory Ltd

dynamic-image's People

Contributors

dieron avatar jaytwo avatar mikhail-fedosenko avatar mzywitza 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

dynamic-image's Issues

Get Byte[] from GeneratedImage

I am using the object module to create an image from different layers, and after am done i want to save it back to the DB as a Byte[].

How do I accomplish this, as I do not see any method from GeneratedImage class, and the documented option was to get a URL.

thanks for the great library.

How to set image quality

Hi,

Can you please tell us how to set the quality parameter while using dynamic image.

Kind regards,

Saved image is black

Hi,
I used the following code, and the saved image is black:

CompositionBuilder builder = new CompositionBuilder(); builder.WithLayer(LayerBuilder.Image.SourceBytes(streamToResize)) .WithGlobalFilter(FilterBuilder.Resize.To(newWidth, newHeight, ResizeMode.UniformFill)); builder.SaveTo(saveToPath);

Have you any idea why the image is black?

Thanks!

picture

cachePath on cache provider

Hi! It seems cachePath attributes want be recognized.

Sorry but i'm new on github: maybe you simply need to (re)add something like this, on Configuration/CachingSettings.cs ?

[ConfigurationProperty("cachePath")]
public string cachePath
{
get { return this["cachePath"] as string; }
set { this["cachePath"] = value; }
}

Win32Exception is thrown when WPF runs out of internal resources

After an AppDomain has been up for a while, DynamicImage sometimes fails to generate an image because of an exception thrown by WPF:

System.ComponentModel.Win32Exception (0x80004005): The operation completed successfully
at MS.Win32.UnsafeNativeMethods.RegisterClassEx(WNDCLASSEX_D wc_d)
at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
at System.Windows.Media.MediaContextNotificationWindow..ctor(MediaContext ownerMediaContext)
at System.Windows.Media.MediaContext..ctor(Dispatcher dispatcher)
at System.Windows.Media.MediaContext.From(Dispatcher dispatcher)
at System.Windows.Media.Imaging.WriteableBitmap.SubscribeToCommittingBatch()
at System.Windows.Media.Imaging.WriteableBitmap.Unlock()
at System.Windows.Media.Imaging.WriteableBitmap.InitFromBitmapSource(BitmapSource source)
at System.Windows.Media.Imaging.WriteableBitmap..ctor(BitmapSource source)
at SoundInTheory.DynamicImage.Util.FastBitmap..ctor(String filename, UriKind uriKind)
at SoundInTheory.DynamicImage.Sources.FileImageSource.GetBitmap()
at SoundInTheory.DynamicImage.Layers.ImageLayer.CreateImage()
at SoundInTheory.DynamicImage.Layer.Process()
at SoundInTheory.DynamicImage.Composition.CreateImage()
at SoundInTheory.DynamicImage.Composition.GenerateImage()
at SoundInTheory.DynamicImage.Caching.ImageUrlGenerator.GetImageUrl(Composition composition)
at SoundInTheory.DynamicImage.Fluent.CompositionBuilder.get_Url()

This looks to be related to the Dispatcher creating internal HwndWrapper objects. There is an SO question and answer here, which suggest that Dispatchers need to be cleaned up:

http://stackoverflow.com/questions/8995588/asp-net-throws-win32exception-when-creating-bitmapimage-cannot-find-file-specif

DynamicImage doesn't explicitly create threads, so there is nowhere obvious to plug that code in. Perhaps DynamicImage could maintain its own thread pool and do all image generation on one of those threads.

Improve error messages for layer / filter parameters

Currently, error messages don't necessarily identify the layer or filter where the error originates. They should also specify whether value is too large or too small, and the allowed range (if applicable).

Image is not displaying for PDF thumbs

``@Html.DynamicImageTag(b => b.WithLayer(
        new PdfLayerBuilder().SourceFileName("~/Content/1.pdf").PageNumber(1)
            .WithFilter(FilterBuilder.Resize.ToWidth(500))
            //.WithFilter(FilterBuilder.Border.Width(1).Fill(Colors.Black))
            .WithFilter(FilterBuilder.DropShadow)
    ))`
public static class HtmlHelperExtensions
    {
        public static HtmlString DynamicImageTag(this HtmlHelper html, Action<CompositionBuilder> callback)
        {
            var tagBuilder = new TagBuilder("img");

            var compositionBuilder = new CompositionBuilder();
            callback(compositionBuilder);
            tagBuilder.Attributes["src"] = compositionBuilder.Url;

            return MvcHtmlString.Create(tagBuilder.ToString(TagRenderMode.SelfClosing));
        }
    }
`

The image url generating is http://localhost:56861/Assets/Images/DynamicImages/1bac431a5fbcacba541c34a24407dbdd94f13506c99074008c3fe5a9ca1ad3cf.jpg

But the image is not displaying

dynamic-image for .NET 3.5

Hi.
I am using your library to create thumbnails for each page of .pdf-files.
Something like this (where variable file is of type File (my own class)):

using SoundInTheory.DynamicImage;
using SoundInTheory.DynamicImage.Fluent;

Composition composition = new Composition();
for (int page = 1; page <= file.PageCount; page++)
{
.PdfLayerBuilder pdfLayerBuilder = new PdfLayerBuilder().SourceFileName(file.PathPDF).PageNumber(page);
composition.Layers.Add(pdfLayerBuilder.ToLayer());
GeneratedImage bitmap = composition.GenerateImage();
///.......
}

My only problem is that the program hosting this is a WinForms client for .NET framework 3.5.
Since I am only using part of your library would it work for me build for .NET 3.5 and simply comment out lines preventing build?
Do you have any recommendations to solve this problem?

Best regards, Kristján

Generate thumbnail from pdf in a different domain

Hi,

I use PdfLayerBuilder to generate thumbnails of pdf files. These files are in my own domain and it works all good. But, now I have the requirement of generating thumbnails from pdfs in a different domain. Is it possible to do using DynamicImage library? or is there any other way to achieve this.

Thanks

Generated url does not load image

Hi

I have converted the App_Start class to be in vb.net and currently able to cache the images in App_Data. When trying to view the image using the url generated by DynamicImage class the image fails to load.

Are there any routes that I need to add to the site or am I able to override the cache location and url path generated by DynamicImage?

I am also using MVC5 but not the MVC method of loading the image.

Thanks

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.