public static bool CoverExistsForSize(string originalFilePath, PhotoFileSize size, PhotoFileClip clip) { return File.Exists(GetPathForSize(originalFilePath, size, clip)); }
public static string GetPathForSize(string originalFilePath, PhotoFileSize size, PhotoFileClip clip) { var fileid = getIdForFilePath(originalFilePath); var folder = size.ToString(); var folderPath = Path.Combine(root_path, folder); if (clip == PhotoFileClip.Square) folderPath = Path.Combine(folderPath, "square"); var filePath = Path.Combine(folderPath, String.Format("{0}.jpg", fileid)); return filePath; }
private static void generatePhotoFile(string imagePath, string resizedPath, PhotoFileSize size, PhotoFileClip clip) { var dir = new DirectoryInfo(Path.GetDirectoryName(resizedPath)); dir.Create(true); using (Bitmap bmp = new Bitmap(imagePath)) { bmp.AutoRotate(); using (BitmapEx resizedBmp = clip == PhotoFileClip.Square ? bmp.GetSquare((int)size) : bmp.GetResized((int)size)) { string thumbnailTempPath = resizedPath + ".tmp"; var encodeParams = new EncoderParameters(1); encodeParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, instance.qualityLevel); resizedBmp.Bitmap.Save(thumbnailTempPath, jgpEncoder, encodeParams); File.Move(thumbnailTempPath, resizedPath); } } }