예제 #1
0
        protected virtual void ProcessRequest(RequestItem request)
        {
            IImage originalImage;

            try {
                using (IImageFile img = imageFileFactory.Create(request.Uri)) {
                    if (request.Width > 0)
                    {
                        originalImage = img.Load(request.Width, request.Height);
                    }
                    else
                    {
                        originalImage = img.Load();
                    }
                }
            } catch (Exception e) {
                Log.Exception(e);
                return;
            }

            if (originalImage == null)
            {
                return;
            }

            request.Result = originalImage;
        }
예제 #2
0
        bool CreateThumbnail(SafeUri thumbnailUri, ThumbnailSize size, IImageFile imageFile)
        {
            var    pixels = size == ThumbnailSize.Normal ? 128 : 256;
            Pixbuf pixbuf;

            try {
                pixbuf = imageFile.Load();
            } catch (Exception e) {
                Log.DebugFormat("Failed loading image for thumbnailing: {0}", imageFile.Uri);
                Log.DebugException(e);
                return(false);
            }

            double scale_x = (double)pixbuf.Width / pixels;
            double scale_y = (double)pixbuf.Height / pixels;
            double scale   = Math.Max(1.0, Math.Max(scale_x, scale_y));
            // Ensures that the minimum value is 1 so that pixbuf.ScaleSimple doesn't return null
            // Seems to only happen in rare(?) cases
            int target_x = Math.Max((int)(pixbuf.Width / scale), 1);
            int target_y = Math.Max((int)(pixbuf.Height / scale), 1);

            var thumb_pixbuf = pixbuf.ScaleSimple(target_x, target_y, InterpType.Bilinear);
            var mtime        = fileSystem.File.GetMTime(imageFile.Uri).ToString();

            thumb_pixbuf.Savev(thumbnailUri.LocalPath, "png",
                               new string [] { ThumbnailService.ThumbUriOpt, ThumbnailService.ThumbMTimeOpt, null },
                               new string [] { imageFile.Uri, mtime });

            pixbuf.Dispose();
            thumb_pixbuf.Dispose();

            return(true);
        }
예제 #3
0
		bool CreateThumbnail (SafeUri thumbnailUri, ThumbnailSize size, IImageFile imageFile)
		{
			var pixels = size == ThumbnailSize.Normal ? 128 : 256;
			Pixbuf pixbuf;
			try {
				pixbuf = imageFile.Load ();
			} catch (Exception e) {
				Log.DebugFormat ("Failed loading image for thumbnailing: {0}", imageFile.Uri);
				Log.DebugException (e);
				return false;
			}

			double scale_x = (double)pixbuf.Width / pixels;
			double scale_y = (double)pixbuf.Height / pixels;
			double scale = Math.Max (1.0, Math.Max (scale_x, scale_y));
			// Ensures that the minimum value is 1 so that pixbuf.ScaleSimple doesn't return null
			// Seems to only happen in rare(?) cases
			int target_x = Math.Max ((int)(pixbuf.Width / scale), 1);
			int target_y = Math.Max ((int)(pixbuf.Height / scale), 1);

			var thumb_pixbuf = pixbuf.ScaleSimple (target_x, target_y, InterpType.Bilinear);
			var mtime = fileSystem.File.GetMTime (imageFile.Uri).ToString ();
			thumb_pixbuf.Savev (thumbnailUri.LocalPath, "png",
				new string [] { ThumbnailService.ThumbUriOpt, ThumbnailService.ThumbMTimeOpt, null },
				new string [] { imageFile.Uri, mtime });

			pixbuf.Dispose ();
			thumb_pixbuf.Dispose ();

			return true;
		}
예제 #4
0
        bool CreateThumbnail(Uri thumbnailUri, ThumbnailSize size, IImageFile imageFile)
        {
            var    pixels = size == ThumbnailSize.Normal ? 128 : 256;
            IImage image;

            try {
                image = imageFile.Load();
            } catch (Exception e) {
                Log.DebugFormat("Failed loading image for thumbnailing: {0}", imageFile.Uri);
                Log.DebugException(e);
                return(false);
            }

            double scale_x = (double)image.Width / pixels;
            double scale_y = (double)image.Height / pixels;
            double scale   = Math.Max(1.0, Math.Max(scale_x, scale_y));
            // Ensures that the minimum value is 1 so that pixbuf.ScaleSimple doesn't return null
            // Seems to only happen in rare(?) cases
            int target_x = Math.Max((int)(image.Width / scale), 1);
            int target_y = Math.Max((int)(image.Height / scale), 1);

            var thumbImage = image as Image <Rgba32>;

            thumbImage.Mutate(x => x.Resize(target_x, target_y));              // pixbuf.ScaleSimple (target_x, target_y, InterpType.Bilinear);
            var mtime = fileSystem.File.GetLastWriteTime(imageFile.Uri).ToString();

            using (var stream = new FileStream(thumbnailUri.LocalPath, FileMode.Create)) {
                thumbImage.SaveAsPng(stream, new PngEncoder());
            }
            // FIXME
            //thumbImage.SaveAsPng (. .Savev (thumbnailUri.LocalPath, "png",
            //	new string[] { ThumbnailService.ThumbUriOpt, ThumbnailService.ThumbMTimeOpt, null },
            //	new string[] { imageFile.Uri.AbsoluteUri, mtime });

            image.Dispose();
            thumbImage.Dispose();

            return(true);
        }