예제 #1
0
        public BaseReturn Validation(ImageValidationDTO dto)
        {
            var result = new BaseReturn();

            try
            {
                using (var image = new MagickImage(dto.Source))
                {
                    if (dto.Type.Equals(ImageValidationDTO.type.absolue) &&
                        image.Width.Equals(dto.Width) &&
                        image.Height.Equals(dto.Height))
                    {
                        result.Ok();
                    }
                    else if (dto.Type.Equals(ImageValidationDTO.type.relative) &&
                             image.Width <= dto.Width &&
                             image.Height <= dto.Height)
                    {
                        result.Ok();
                    }
                }
            }
            catch (Exception ex)
            {
                result.AddMessage("[error]", ex.Message);
            }

            return(result);
        }
예제 #2
0
        public BaseReturn Crop(ImageCropDTO dto)
        {
            var result = new BaseReturn();

            try
            {
                using (var image = new MagickImage(dto.Source))
                {
                    image.Crop(dto.Width, dto.Height);
                    image.Write(dto.FullDestination);
                }

                if (dto.DeleteSource)
                {
                    File.Delete(dto.Source);
                }

                result.Ok();
            }
            catch (Exception ex)
            {
                result.AddMessage("[error]", ex.Message);
            }

            return(result);
        }