Skip to content

Commit

Permalink
Merge pull request #11 from LazZiya/vNext
Browse files Browse the repository at this point in the history
V next
  • Loading branch information
LazZiya authored Aug 2, 2021
2 parents fc9ea0e + 6d3fd6e commit 6cdb31d
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 17 deletions.
1 change: 0 additions & 1 deletion LazZiya.ImageResize/Animated/AnimatedImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ public static AnimatedImage FromHBitmap(IntPtr hbitmap, IntPtr hpalatte)
/// Save animated gif
/// </summary>
/// <param name="path"></param>
/// <param name="repeat">Frame delay in milliseconds</param>
public void SaveAs(string path)
{
var e = new AnimatedGifEncoder();
Expand Down
4 changes: 2 additions & 2 deletions LazZiya.ImageResize/ImageResize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ public static Image Resize(this Image img, Rectangle source, Rectangle target, G
using (var ms = new MemoryStream())
{
outputImage.Save(ms, img.RawFormat);
return Image.FromStream(ms);
return Image.FromStream(ms).ReserveOriginalRotation(img);
}
}

return Image.FromHbitmap(outputImage.GetHbitmap());
return Image.FromHbitmap(outputImage.GetHbitmap()).ReserveOriginalRotation(img);
}
}
}
Expand Down
72 changes: 72 additions & 0 deletions LazZiya.ImageResize/ImageRotation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Drawing;
using System.Linq;

namespace LazZiya.ImageResize
{
/// <summary>
/// Image rotation operations
/// </summary>
public static class ImageRotation
{
private const int exifOrientationId = 0x112;

/// <summary>
/// Keep resized image rotation as the original image
/// </summary>
/// <param name="img"></param>
/// <param name="originalImage"></param>
/// <returns></returns>
public static Image ReserveOriginalRotation(this Image img, Image originalImage)
{
if (!originalImage.PropertyIdList.Contains(exifOrientationId))
return img;

var rotation = originalImage.GetPropertyItem(exifOrientationId);
int val = BitConverter.ToUInt16(rotation.Value, 0);
var rot = RotateFlipType.RotateNoneFlipNone;

if (val == 3 || val == 4)
rot = RotateFlipType.Rotate180FlipNone;
else if (val == 5 || val == 6)
rot = RotateFlipType.Rotate90FlipNone;
else if (val == 7 || val == 8)
rot = RotateFlipType.Rotate270FlipNone;

if (val == 2 || val == 4 || val == 5 || val == 7)
rot |= RotateFlipType.RotateNoneFlipX;

if (rot != RotateFlipType.RotateNoneFlipNone)
img.RotateFlip(rot);

return img;
}

/// <summary>
/// Rotate and/or flip the image
/// </summary>
/// <param name="img"></param>
/// <param name="rotateFlipType"></param>
/// <returns></returns>
public static Image RotateFlipImage(this Image img, RotateFlipType rotateFlipType)
{
img.RotateFlip(rotateFlipType);
return img;
}

/// <summary>
/// Rotate and/or flip the image
/// </summary>
/// <param name="img"></param>
/// <param name="condition"></param>
/// <param name="rotateFlipType"></param>
/// <returns></returns>
public static Image RotateFlipImageIf(this Image img, bool condition, RotateFlipType rotateFlipType)
{
if(condition)
img.RotateFlip(rotateFlipType);

return img;
}
}
}
19 changes: 7 additions & 12 deletions LazZiya.ImageResize/LazZiya.ImageResize.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,17 @@
<PackageTags>asp.net,core,.net,dotnet,image,resize,text,overlay</PackageTags>
<RepositoryUrl>https://github.com/LazZiya/ImageResize</RepositoryUrl>
<PackageProjectUrl>https://docs.ziyad.info/en/LazZiya.ImageResize/v4.0/index.md</PackageProjectUrl>
<VersionPrefix>4.0.0</VersionPrefix>
<VersionPrefix>4.1.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<FileVersion>4.0.0.0</FileVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<FileVersion>4.1.0.0</FileVersion>
<PackageReleaseNotes>
Fixed:
- Linux support (https://github.com/LazZiya/ImageResize/issues/1)
- Rotate the photo #10 (https://github.com/LazZiya/ImageResize/issues/10)

New Features:
- New - "Conditional" resizing methods: The resize will done depending on a conditional parameter.
- New - "AddFrame" method: Draw a frame (border) around the image and specify distance, color, etc.
- New - "Mask" method: Applies a mask over the image.
- New - "AnimatedImage" - Edit animated gif images (resize, text watewrmark, image water etc.)

Other updates:
- Update ref for System.Drawing.Common https://github.com/dotnet/core/issues/3244
- New - "RotateFlipImage" method: rotate or flip images
- New - "RotateFlipImageIf" method: conditionally rotate or flip images

- See all details in the docs https://docs.ziyad.info
</PackageReleaseNotes>
Expand Down
31 changes: 30 additions & 1 deletion LazZiya.ImageResize/LazZiya.ImageResize.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 30 additions & 1 deletion LazZiya.ImageResize/files/LazZiya.ImageResize.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6cdb31d

Please sign in to comment.