LayoutImageMgr.evalImg (param, creator)
function checks if image fits to the minimal needs

  • Parameter Obj:
    Object containing the properties needed for creating a new Image
  • Parameter Obj:
    User-Object creating this image
  • Returns
    Obj Object containing two properties: - error (boolean): true if error happened, false if everything went fine - message (String): containing a message to user
Sourcecode in LayoutImageMgr/objectFunctions.js:
1:   function evalImg(param, creator) {
2:      if (param.uploadError) {
3:         // looks like the file uploaded has exceeded uploadLimit ...
4:         throw new Exception("imageFileTooBig");
5:      } else if (!param.rawimage || param.rawimage.contentLength == 0) {
6:         // looks like nothing was uploaded ...
7:         throw new Exception("imageNoUpload");
8:      } else if (param.rawimage && (!param.rawimage.contentType || !evalImgType(param.rawimage.contentType))) {
9:         // whatever the user has uploaded wasn't recognized as an image
10:        throw new Exception("imageNoImage");
11:     }
12:  
13:     var newImg = new LayoutImage(creator);
14:     // if no alias given try to determine it
15:     if (!param.alias)
16:        newImg.alias = buildAliasFromFile(param.rawimage, this);
17:     else {
18:        if (!param.alias.isFileName())
19:           throw new Exception("noSpecialChars");
20:        newImg.alias = buildAlias(param.alias, this);
21:     }
22:     // store properties necessary for saving image on disk
23:     newImg.filename = newImg.alias;
24:     // save/resize the image
25:     var dir = this._parent.getStaticDir();
26:     newImg.save(param.rawimage, dir);
27:     // the fullsize-image is on disk, so we add the image-object (and create the thumbnail-image too)
28:     newImg.alttext = param.alttext;
29:     if (!this.add(newImg))
30:        throw new Exception("imageAdd");
31:     // the fullsize-image is stored, so we check if a thumbnail should be created too
32:     if (newImg.width > THUMBNAILWIDTH)
33:        newImg.createThumbnail(param.rawimage, dir);
34:     var result = new Message("imageCreate", newImg.alias);
35:     result.url = newImg.href();
36:     return result;
37:  }