Example #1
0
 public ImageController(
     PreviewFacade preview,
     IImageFormat[] formats,
     IUserAuthentication authentication,
     IImageRequestStrategy strategy
     )
     : base(authentication)
 {
     this.preview = preview;
     this.formats = formats;
     this.strategy = strategy;
 }
Example #2
0
        public ImageCache(
            ILocation cacheRoot,
            IImageFormat cacheFormat,
            IImageLoader imageLoader,
            ICacheDependencyProvider[] dependencyProviders
            )
        {
            this.CacheRoot = cacheRoot;

            this.CacheFormat = cacheFormat;
            this.imageLoader = imageLoader;
            this.dependencyProviders = dependencyProviders;
        }
Example #3
0
 /// <summary>
 /// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
 /// </summary>
 /// <param name="stream">The stream containing image information.</param>
 /// <param name="format">The format type of the decoded image.</param>
 /// <exception cref="ArgumentNullException">The stream is null.</exception>
 /// <exception cref="NotSupportedException">The stream is not readable.</exception>
 /// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
 /// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
 /// <typeparam name="TPixel">The pixel format.</typeparam>
 /// <returns>A new <see cref="Image{TPixel}"/>.</returns>
 public static Image <TPixel> Load <TPixel>(Stream stream, out IImageFormat format)
     where TPixel : unmanaged, IPixel <TPixel>
 => Load <TPixel>(Configuration.Default, stream, out format);
Example #4
0
 /// <inheritdoc/>
 public void Save(Stream stream, IImageFormat format)
 {
     Guard.NotNull(stream, nameof(stream));
     format.Encoder.Encode(this, stream);
 }
Example #5
0
 /// <summary>
 /// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
 /// </summary>
 /// <param name="path">The file path to the image.</param>
 /// <param name="format">The mime type of the decoded image.</param>
 /// <exception cref="NotSupportedException">
 /// Thrown if the stream is not readable nor seekable.
 /// </exception>
 /// <typeparam name="TPixel">The pixel format.</typeparam>
 /// <returns>A new <see cref="Image{TPixel}"/>.</returns>
 public static Image <TPixel> Load <TPixel>(string path, out IImageFormat format)
     where TPixel : unmanaged, IPixel <TPixel>
 {
     return(Load <TPixel>(Configuration.Default, path, out format));
 }
Example #6
0
 /// <summary>
 /// Load a new instance of <see cref="Image{TPixel}"/> from the given encoded byte array.
 /// </summary>
 /// <param name="data">The byte array containing image data.</param>
 /// <param name="format">The mime type of the decoded image.</param>
 /// <typeparam name="TPixel">The pixel format.</typeparam>
 /// <returns>A new <see cref="Image{TPixel}"/>.</returns>
 public static Image <TPixel> Load <TPixel>(byte[] data, out IImageFormat format)
     where TPixel : struct, IPixel <TPixel>
 => Load <TPixel>(Configuration.Default, data, out format);
Example #7
0
        /// <summary>
        /// Load a new instance of <see cref="Image{TPixel}"/> from the given encoded byte array.
        /// </summary>
        /// <param name="configuration">The configuration options.</param>
        /// <param name="data">The byte array containing encoded image data.</param>
        /// <param name="format">The <see cref="IImageFormat"/> of the decoded image.</param>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <exception cref="ArgumentNullException">The configuration is null.</exception>
        /// <exception cref="ArgumentNullException">The data is null.</exception>
        /// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
        /// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
        /// <returns>A new <see cref="Image{TPixel}"/>.</returns>
        public static Image <TPixel> Load <TPixel>(Configuration configuration, byte[] data, out IImageFormat format)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            Guard.NotNull(data, nameof(data));

            using (var stream = new MemoryStream(data, 0, data.Length, false, true))
            {
                return(Load <TPixel>(configuration, stream, out format));
            }
        }
        /// <summary>
        /// Reads the raw image information from the specified stream without fully decoding it.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="stream">The image stream to read the information from.</param>
        /// <param name="format">The format type of the decoded image.</param>
        /// <exception cref="ArgumentNullException">The configuration is null.</exception>
        /// <exception cref="ArgumentNullException">The stream is null.</exception>
        /// <exception cref="NotSupportedException">The stream is not readable.</exception>
        /// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
        /// <returns>
        /// The <see cref="IImageInfo"/> or null if a suitable info detector is not found.
        /// </returns>
        public static IImageInfo Identify(Configuration configuration, Stream stream, out IImageFormat format)
        {
            (IImageInfo ImageInfo, IImageFormat Format)data = WithSeekableStream(configuration, stream, s => InternalIdentity(s, configuration ?? Configuration.Default));

            format = data.Format;
            return(data.ImageInfo);
        }
Example #9
0
 /// <summary>
 /// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given stream.
 /// </summary>
 /// <param name="config">The config for the decoder.</param>
 /// <param name="stream">The stream containing image information.</param>
 /// <param name="format">the mime type of the decoded image.</param>
 /// <exception cref="NotSupportedException">
 /// Thrown if the stream is not readable nor seekable.
 /// </exception>
 /// <returns>A new <see cref="Image{Rgba32}"/>.</returns>>
 public static Image <Rgba32> Load(Configuration config, Stream stream, out IImageFormat format) => Load <Rgba32>(config, stream, out format);
Example #10
0
 public LoadImageFromUrlResult(Image <Rgba32> image, IImageFormat imageFormat)
 {
     this.Image       = image;
     this.ImageFormat = imageFormat;
 }
Example #11
0
 private static byte[] ImageToByteArray(Image <Rgba32> image, IImageFormat imageFormat)
 {
     using var ms = new MemoryStream();
     image.Save(ms, imageFormat);
     return(ms.ToArray());
 }
Example #12
0
 private static byte[] ImageToBytes(Image image, IImageFormat format)
 {
     using MemoryStream ms = new MemoryStream();
     image.Save(ms, format);
     return(ms.ToArray());
 }
Example #13
0
        static PhpGdImageResource imagecreatecommon(int x_size, int y_size, IConfigurationModule configuration, IImageFormat format)
        {
            if (x_size <= 0 || y_size <= 0)
            {
                PhpException.Throw(PhpError.Warning, string.Format(Resources.invalid_image_dimensions));
                return(null);
            }

            return(new PhpGdImageResource(x_size, y_size, configuration, format));
        }
Example #14
0
        /// <summary>
        /// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
        /// </summary>
        /// <param name="configuration">The configuration options.</param>
        /// <param name="stream">The stream containing image information.</param>
        /// <param name="format">The format type of the decoded image.</param>
        /// <exception cref="ArgumentNullException">The configuration is null.</exception>
        /// <exception cref="ArgumentNullException">The stream is null.</exception>
        /// <exception cref="NotSupportedException">The stream is not readable.</exception>
        /// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
        /// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public static Image <TPixel> Load <TPixel>(Configuration configuration, Stream stream, out IImageFormat format)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            (Image <TPixel> Image, IImageFormat Format)data = WithSeekableStream(configuration, stream, s => Decode <TPixel>(s, configuration));

            format = data.Format;

            if (data.Image != null)
            {
                return(data.Image);
            }

            var sb = new StringBuilder();

            sb.AppendLine("Image cannot be loaded. Available decoders:");

            foreach (KeyValuePair <IImageFormat, IImageDecoder> val in configuration.ImageFormatsManager.ImageDecoders)
            {
                sb.AppendFormat(" - {0} : {1}{2}", val.Key.Name, val.Value.GetType().Name, Environment.NewLine);
            }

            throw new UnknownImageFormatException(sb.ToString());
        }
            public void WhenNoMatchingFormatFound_ReturnsNull()
            {
                IImageFormat type = Image.DetectFormat(new Configuration(), this.DataStream);

                Assert.Null(type);
            }
 /// <summary>
 /// Reads the raw image information from the specified stream without fully decoding it.
 /// </summary>
 /// <param name="stream">The image stream to read the header from.</param>
 /// <param name="format">The format type of the decoded image.</param>
 /// <exception cref="ArgumentNullException">The stream is null.</exception>
 /// <exception cref="NotSupportedException">The stream is not readable.</exception>
 /// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
 /// <returns>
 /// The <see cref="IImageInfo"/> or null if a suitable info detector is not found.
 /// </returns>
 public static IImageInfo Identify(Stream stream, out IImageFormat format)
 => Identify(Configuration.Default, stream, out format);
Example #17
0
 /// <summary>
 /// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
 /// </summary>
 /// <param name="stream">The stream containing image information.</param>
 /// <param name="format">the mime type of the decoded image.</param>
 /// <exception cref="NotSupportedException">
 /// Thrown if the stream is not readable nor seekable.
 /// </exception>
 /// <typeparam name="TPixel">The pixel format.</typeparam>
 /// <returns>A new <see cref="Image{TPixel}"/>.</returns>>
 public static Image <TPixel> Load <TPixel>(Stream stream, out IImageFormat format)
     where TPixel : struct, IPixel <TPixel>
 {
     return(Load <TPixel>(null, stream, out format));
 }
Example #18
0
        /// <summary>
        /// html view model
        /// </summary>
        /// <param name="captcha"></param>
        /// <param name="imagePath">Get pictures using HTTP</param>
        /// <param name="format">Get pictures using Base64</param>
        /// <returns></returns>
        public static CaptchaViewModel ToViewModel(this CaptchaImage captcha, string validatePath, Action <CaptchaViewModel> imagePath = null, bool hasBackground = false, IImageFormat format = null)
        {
            if (captcha == null)
            {
                return(new CaptchaViewModel());
            }
            var model = new CaptchaViewModel();

            model.Extension = captcha.Extension;
            model.Index     = JsonSerializer.Serialize(captcha.Index);
            model.Change    = JsonSerializer.Serialize(captcha.Change);
            model.Width     = captcha.Backgorund.Width;
            model.Height    = captcha.Backgorund.Height;
            model.Row       = captcha.Row;
            model.Col       = captcha.Col;
            model.X         = captcha.Points.Count;
            model.validate  = validatePath;
            model.Tips      = captcha.Tips;
            if (imagePath != null)
            {
                model.IsAction = true;
                imagePath(model);
            }
            else
            {
                model.IsAction = false;
                if (format == null)
                {
                    format = JpegFormat.Instance;
                }
                model.Gap   = captcha.Gap?.ToBase64String(PngFormat.Instance);
                model.BgGap = captcha.GapBackground?.ToBase64String(model.Height != captcha.GapBackground.Height?PngFormat.Instance:format);
                if (hasBackground)
                {
                    model.Full = captcha.Backgorund?.ToBase64String(format);
                }
            }

            model.Type = captcha.Type;
            model.Tk   = captcha.Token;
            model.Name = captcha.Name;
            return(model);
        }
Example #19
0
        /// <summary>
        /// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
        /// </summary>
        /// <param name="config">The configuration options.</param>
        /// <param name="stream">The stream containing image information.</param>
        /// <param name="format">the mime type of the decoded image.</param>
        /// <exception cref="NotSupportedException">
        /// Thrown if the stream is not readable nor seekable.
        /// </exception>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <returns>A new <see cref="Image{TPixel}"/>.</returns>>
        public static Image <TPixel> Load <TPixel>(Configuration config, Stream stream, out IImageFormat format)
            where TPixel : struct, IPixel <TPixel>
        {
            config = config ?? Configuration.Default;
            var data = WithSeekableStream(stream, s => Decode <TPixel>(s, config));

            format = data.Item2;

            if (data.Item1 != null)
            {
                return(data.Item1);
            }

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Image cannot be loaded. Available decoders:");

            foreach (KeyValuePair <IImageFormat, IImageDecoder> val in config.ImageDecoders)
            {
                stringBuilder.AppendLine($" - {val.Key.Name} : {val.Value.GetType().Name}");
            }

            throw new NotSupportedException(stringBuilder.ToString());
        }
Example #20
0
 /// <summary>
 /// Reads the raw image information from the specified stream without fully decoding it.
 /// </summary>
 /// <param name="data">The byte array containing encoded image data to read the header from.</param>
 /// <param name="format">The format type of the decoded image.</param>
 /// <exception cref="ArgumentNullException">The data is null.</exception>
 /// <exception cref="NotSupportedException">The data is not readable.</exception>
 /// <returns>
 /// The <see cref="IImageInfo"/> or null if suitable info detector not found.
 /// </returns>
 public static IImageInfo Identify(byte[] data, out IImageFormat format) => Identify(Configuration.Default, data, out format);
Example #21
0
 /// <summary>
 /// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given stream.
 /// </summary>
 /// <param name="stream">The stream containing image information.</param>
 /// <param name="format">the mime type of the decoded image.</param>
 /// <exception cref="NotSupportedException">
 /// Thrown if the stream is not readable nor seekable.
 /// </exception>
 /// <returns>A new <see cref="Image{Rgba32}"/>.</returns>>
 public static Image <Rgba32> Load(Stream stream, out IImageFormat format) => Load <Rgba32>(stream, out format);
Example #22
0
 /// <summary>
 /// Load a new instance of <see cref="Image{TPixel}"/> from the given encoded byte array.
 /// </summary>
 /// <param name="config">The configuration options.</param>
 /// <param name="data">The byte array containing encoded image data.</param>
 /// <param name="format">The <see cref="IImageFormat"/> of the decoded image.</param>
 /// <typeparam name="TPixel">The pixel format.</typeparam>
 /// <returns>A new <see cref="Image{TPixel}"/>.</returns>
 public static Image <TPixel> Load <TPixel>(Configuration config, byte[] data, out IImageFormat format)
     where TPixel : struct, IPixel <TPixel>
 {
     using (var stream = new MemoryStream(data))
     {
         return(Load <TPixel>(config, stream, out format));
     }
 }
Example #23
0
        /// <summary>
        /// By reading the header on the provided stream this calculates the images format.
        /// </summary>
        /// <param name="stream">The image stream to read the header from.</param>
        /// <param name="config">The configuration.</param>
        /// <param name="format">The IImageFormat.</param>
        /// <returns>The image format or null if none found.</returns>
        private static IImageDecoder DiscoverDecoder(Stream stream, Configuration config, out IImageFormat format)
        {
            format = InternalDetectFormat(stream, config);

            return(format != null
                ? config.ImageFormatsManager.FindDecoder(format)
                : null);
        }
Example #24
0
 /// <summary>
 /// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
 /// </summary>
 /// <param name="config">The configuration options.</param>
 /// <param name="path">The file path to the image.</param>
 /// <param name="format">The mime type of the decoded image.</param>
 /// <exception cref="NotSupportedException">
 /// Thrown if the stream is not readable nor seekable.
 /// </exception>
 /// <typeparam name="TPixel">The pixel format.</typeparam>
 /// <returns>A new <see cref="Image{TPixel}"/>.</returns>
 public static Image <TPixel> Load <TPixel>(Configuration config, string path, out IImageFormat format)
     where TPixel : unmanaged, IPixel <TPixel>
 {
     using (Stream stream = config.FileSystem.OpenRead(path))
     {
         return(Load <TPixel>(config, stream, out format));
     }
 }
            public void FromFileSystemPath_GlobalConfiguration()
            {
                IImageFormat type = Image.DetectFormat(ActualImagePath);

                Assert.Equal(ExpectedGlobalFormat, type);
            }
Example #26
0
		public void AddImageFormat(IImageFormat format){
			imageFormats.Add(format);
		}
            public void FromFileSystemPath_CustomConfiguration()
            {
                IImageFormat type = Image.DetectFormat(this.LocalConfiguration, this.MockFilePath);

                Assert.Equal(this.LocalImageFormat, type);
            }
            public void FromStream_CustomConfiguration()
            {
                IImageFormat type = Image.DetectFormat(this.LocalConfiguration, this.DataStream);

                Assert.Equal(this.LocalImageFormat, type);
            }
Example #29
0
 /// <summary>
 /// Decode a new instance of the <see cref="Image"/> class from the given stream.
 /// The pixel format is selected by the decoder.
 /// </summary>
 /// <param name="stream">The stream containing image information.</param>
 /// <param name="format">The format type of the decoded image.</param>
 /// <exception cref="ArgumentNullException">The stream is null.</exception>
 /// <exception cref="NotSupportedException">The stream is not readable.</exception>
 /// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
 /// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
 /// <returns>The <see cref="Image"/>.</returns>
 public static Image Load(Stream stream, out IImageFormat format)
 => Load(Configuration.Default, stream, out format);