<commit_before>﻿namespace Figlut.Server.Toolkit.Utilities
{
    #region Using Directives

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;
    using System.Drawing.Drawing2D;

    #endregion //Using Directives

    public class ImageHandler
    {
        #region Methods

        /// <summary>
        /// Converts an Image to a byte array.
        /// </summary>
        /// <param name="image">An image to convert.</param>
        /// <returns>Returns a byte array.</returns>
        public byte[] GetBytesFromImage(Image image)
        {
            using (var ms = new MemoryStream())
            {
                image.Save(ms, image.RawFormat);
                return ms.ToArray();
            }
        }

        public static void RotateImageFile(
    string filePath,
    RotateFlipType rotateFlipType)
        {
            FileSystemHelper.ValidateFileExists(filePath);
            using (Image image = Image.FromFile(filePath))
            {
                image.RotateFlip(rotateFlipType);
                image.Save(filePath, ImageFormat.Png);
            }
        }

        /// <summary>
        /// Method to resize, convert and save the image.
        /// </summary>
        /// <param name="image">Bitmap image.</param>
        /// <param name="maxWidth">resize width.</param>
        /// <param name="maxHeight">resize height.</param><commit_msg>Changed GetBytesFromImage to a static method.<commit_after>﻿namespace Figlut.Server.Toolkit.Utilities
{
    #region Using Directives

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;
    using System.Drawing.Drawing2D;

    #endregion //Using Directives

    public class ImageHandler
    {
        #region Methods

        /// <summary>
        /// Converts an Image to a byte array.
        /// </summary>
        /// <param name="image">An image to convert.</param>
        /// <returns>Returns a byte array.</returns>
        public static byte[] GetBytesFromImage(Image image)
        {
            using (var ms = new MemoryStream())
            {
                image.Save(ms, image.RawFormat);
                return ms.ToArray();
            }
        }

        public static void RotateImageFile(
    string filePath,
    RotateFlipType rotateFlipType)
        {
            FileSystemHelper.ValidateFileExists(filePath);
            using (Image image = Image.FromFile(filePath))
            {
                image.RotateFlip(rotateFlipType);
                image.Save(filePath, ImageFormat.Png);
            }
        }

        /// <summary>
        /// Method to resize, convert and save the image.
        /// </summary>
        /// <param name="image">Bitmap image.</param>
        /// <param name="maxWidth">resize width.</param>
        /// <param name="maxHeight">resize height.</param>
{'fraction_non_alphanumeric': 0.11191335740072202, 'fraction_numerical': 0.0006563833278634722, 'mean_word_length': 1.7963302752293577, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4334342', 'n_tokens_mistral': 815, 'n_tokens_neox': 794, 'n_words': 195}