public static string GetUrlFor(string photoId, PhotoFileSize size) { var imgFile = PhotoLibrary.GetPhoto(photoId).MediaFilePath; var thumbFile = PhotoFileSpec.GetPathForSize(imgFile, size, PhotoFileProvider.ThumbnailClip); var fileDate = DateTime.Now; if (File.Exists(thumbFile)) fileDate = File.GetCreationTime(thumbFile); return String.Format("PhotoFile.aspx?id={0}&size={1}&date={2}", HttpUtility.UrlEncode(photoId), size.ToString(), fileDate.ToString("yyyyMMddHHmmss")); }
public static string GetResizedPhoto(string imagePath, PhotoFileSize size) { PhotoFileClip clip = size == PhotoFileSize.Thumbnail ? ThumbnailClip : PhotoFileClip.No; string thumbnailPath = PhotoFileSpec.GetPathForSize(imagePath, size, clip); if (!File.Exists(thumbnailPath)) { generatePhotoFile(imagePath, thumbnailPath, size, clip); } return thumbnailPath; }
public static bool CoverExistsForSize(string originalFilePath, PhotoFileSize size) { return CoverExistsForSize(originalFilePath, size, PhotoFileClip.No); }
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; }
public static string GetPathForSize(string originalFilePath, PhotoFileSize size) { return GetPathForSize(originalFilePath, size, PhotoFileClip.No); }
public static bool CoverExistsForSize(string originalFilePath, PhotoFileSize size, PhotoFileClip clip) { return File.Exists(GetPathForSize(originalFilePath, size, clip)); }
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); } } }
private static string getFile(IPhotoInfo photo, PhotoFileSize size) { return size != PhotoFileSize.Raw ? PhotoFileProvider.GetResizedPhoto(photo.MediaFilePath, size) : photo.MediaFilePath; }
public PhotoFileResult(IPhotoInfo photo, PhotoFileSize size) : base(getFile(photo, size), "image/jpeg") { }
public static Size GetPhotoSize(string imagePath, PhotoFileSize size) { if (ThumbnailClip == PhotoFileClip.Square && size == PhotoFileSize.Thumbnail) return new Size((int)size, (int)size); else return JpegHeaderReader.GetDimensions(GetResizedPhoto(imagePath, size)); }