This project has moved. For the latest updates, please go here.

On the first step you have to add the upload section to your config file:

<configuration>
  <configSections>
    <section name="upload" type="OmidID.IO.SaveMedia.Config.UploadSettings, OmidID.IO.SaveMedia, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
  </configSections>
</configuration>

now you can add the upload section to your config file:

 

<configuration>
  <upload default="">
    <items>
      ...
    </items>
    <modules>
      ...
    </modules>
    <handlers>
      ...
    </handlers>
  </upload>
</configuration>

 

1. The items section:

In this section you can have multiple setting for you upload.
Those setting can be use in the Turbo Upload also.

<add path="~/UserGallery" extentions="jpg,jpeg,png,bmp,gif,tif,tiff"
     maximumSize="1048576" checkImageSetting="true" keepOrginalImage="true" customFileNameType=""
     generateFileName="Auto" name="UserGallery">
   <imageSetting>
      ...
   </imageSetting>
</add>
Property Description
path the absolute path for save the uploaded file
extentions valid file for save and upload
maximumSize the maximum allow size to upload or save the file
checkImageSetting if file will be a image and also imageSetting have any items is will be resize and affect the uploaded image
keepOrginalImage if it's will be false the file will be delete after resize; true otherwise (* not recommend to set false *)
generateFileName GUID:         Generate the new guid for uploaded file name
Overwrite:   Overwrite the file if the same name is exist in the path
Auto:          Automatically rename the new file to numeric, ex: File.jpg, File_1.jpg, File_2.jpg, ...
Custom:     You need a class so inherited of OmidID.IO.SaveMedia.CustomFileNameProvider
name for file the setting in the collection
customFileNameType after you set the generateFileName to Custom you must set this property to your type name. ex: "ExampleProject.MyCustomFileName, ExampleProject" go to: 1.2 section

1.1. ImageSetting Item

<add name="160" saveAs="JPEG" background="#FFFFFF" saveImmidately="true"
     width="160" height="160" x="0" y="0" alpha="1" resolutionX="96"
     resolutionY="96" changeResolution="false" zoom="Corp">
   <foreground ... />
</add>
Property  Description
name find the save item in the collection and sub folder name
saveAs change the file type if need to change
background background image path or background color. ex:~/images/frame.png, ex:#ffffff
saveImmidately if true the image file will be resize and save at the upload time otherwise you have to use handler or runtime generator
width new size for width
height new size for height
x this property will use when you using the background (x position of background to start drawing image)
y this property will use when you using the background (y position of background to start drawing image)
zoom
Tile tile the image in the selected area (x, y, width, height)
Center insert the image in center of the background
Stretch stretch the image to width and height
Zoom zoom the image between the width and height
CenterIfNoZoom put the image in the center if image is smaller than area
Corp zoom to small size and remove the other area (facebook style)
alpha opacity of your image between 0.0 - 1.0
resolutionX new resolution for width
resolutionY new resolution for height
changeResolution if true the resolution will be change on save.
foreground go to 1.1.1 section

 

1.1.1 foreground:

<foreground path="~/Images/Watermark.png" width="800" height="600" x="0" y="0" alpha="1" resolutionX="96" resolutionY="96" changeResolution="false" />
Property  Description
width new size for width
height new size for height
x this property will use when you using the background (x position of background to start drawing image)
y this property will use when you using the background (y position of background to start drawing image)
zoom
Tile tile the image in the selected area (x, y, width, height)
Center insert the image in center of the background
Stretch stretch the image to width and height
Zoom zoom the image between the width and height
CenterIfNoZoom put the image in the center if image is smaller than area
Corp zoom to small size and remove the other area (facebook style)
alpha opacity of your image between 0.0 - 1.0
resolutionX new resolution for width
resolutionY new resolution for height
changeResolution if true the resolution will be change on save.

 

1.2 customFileNameType:

For generate custom file name we have to create a new class inherited of OmidID.IO.SaveMedia.CustomFileNameProvider and set the args.SaveAs to new file name,
Follow the example:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace MvcApplication1 {
    public class CustomFileName : OmidID.IO.SaveMedia.CustomFileNameProvider {

        public override void GenerateFileName(OmidID.IO.SaveMedia.SavingFileEventArgs args) {
            var Extention = Path.GetExtension(args.FileName);
            var filename = Guid.NewGuid().ToString() + Extention;
            var p = Path.Combine(args.Path, filename);


            args.AppPath += (args.AppPath.EndsWith("/") ? "" : "/") + filename;
            args.SaveAs = p;
        }

    }
}

 

 

2. The modules section:

There is the a HttpModule in the Manage Media so that control your deleted or not generate image.
This module working with Regular expression to detect the url and check the image. you can add the control image exist like this:

<add match="./UserGallery/(.*)/(.*)" item="UserGallery" generateFile="true" name="CheckGallery" />
Properrty Description
match regular expression for detect the url
item item name from item collection go to section 1
generateFile if true, the file will be generate after check exist
name for find the config in the collection

 

 

2. The handler section:

There is the a HttpHandler for generate the image realtime.
This handler working with Regular expression to detect the url:

<add match="./UserGallery/(.*)/(.*)" item="UserGallery" generateFile="true" name="CheckGallery" />
Properrty Description
match regular expression for detect the url
item item name from item collection go to section 1
generateFile if true, the file will be generate after check exist
name for find the config in the collection

Last edited Jul 28, 2011 at 11:51 AM by OmidID, version 1

Comments

No comments yet.