コード例 #1
0
ファイル: ImagesController.cs プロジェクト: cmcd74/SavvyCMS
        private static string DynamicImage(PictureActiveField pictureField, int width, int height, string cropStyle)
        {
            var    moddate          = pictureField.Record.Advanced.DateModified;
            var    uniqueKey        = pictureField.Record.GetTableName() + "_" + pictureField.Record.ID_Field.ValueObject + "_" + pictureField.Name + "_" + width + "x" + height + "_" + cropStyle;
            var    keywords         = (pictureField.Record.GetName());
            string originalFilename = pictureField.ToString();

            CheckTable();
            //var sql = new Sql();
            //var record = new ActiveRecord("DynamicImage", "");
            //record.LoadData();
            //var imgRecord = ActiveRecordLoader.LoadByField<ActiveRecord>("UniqueKey", uniqueKey, "DynamicImage", Otherwise.New);
            //var imgRecord = ActiveRecordLoader.Load<ActiveRecord>(new Sql("select * from DynamicImage where UniqueKey=", uniqueKey.SqlizeText()), "DynamicImage");
            var imgRecord = Models.DynamicImage.LoadByUniqueKey(uniqueKey);

            if (imgRecord == null)
            {
                imgRecord = new DynamicImage();
            }
            if (imgRecord.IsNewRecord || imgRecord["ImageModDate"].ConvertToDate() != moddate)
            {
                var currentVersion = imgRecord["Version"].ToInt(0);
                if (!imgRecord.IsNewRecord)
                {
                    // delete existing file to save space
                    FileSystem.DeleteAttachment("DynamicImage/" + imgRecord.ID_Field.ValueObject + "_" + currentVersion + ".png");
                }
                // create the record
                imgRecord["UniqueKey"].ValueObject        = uniqueKey;
                imgRecord["ImageUrl"].ValueObject         = Fmt.Crunch(keywords);
                imgRecord["Version"].ValueObject          = currentVersion + 1;
                imgRecord["CropStyle"].ValueObject        = cropStyle;
                imgRecord["Width"].ValueObject            = width;
                imgRecord["Height"].ValueObject           = height;
                imgRecord["OriginalFilename"].ValueObject = originalFilename;
                imgRecord["ImageModDate"].ValueObject     = moddate;
                imgRecord.Save();
            }
            // return file name
            return(Web.Root + "i/" + imgRecord.ID_Field.ValueObject + "_" + imgRecord["Version"] + "/" + imgRecord["ImageUrl"] + ".png");
        }
コード例 #2
0
ファイル: ImagesController.cs プロジェクト: cmcd74/SavvyCMS
 /// <summary>
 /// Returns an img src for a proportionately resized version of the given image. Will scale and add whitespace to pad to exact size.
 /// Auto cache date and file name.
 /// </summary>
 public static string DynamicExact(PictureActiveField pictureField, int width, int height)
 {
     return(DynamicImage(pictureField, width, height, "crop"));
 }
コード例 #3
0
ファイル: ImagesController.cs プロジェクト: cmcd74/SavvyCMS
 /// <summary>
 /// Returns an img src for proportionately resized version of given image at the given max size. May be smaller.
 /// Auto cache date and file name.
 /// </summary>
 public static string DynamicWithin(PictureActiveField pictureField, int maxWidth, int maxHeight)
 {
     return(DynamicImage(pictureField, maxWidth, maxHeight, "within"));
 }