Changes between Version 3 and Version 4 of Howto/WorkingWithImages/CodeExamples

Show
Ignore:
Author:
lakiboy (IP: 217.199.114.172)
Timestamp:
12/28/06 06:33:07 (7 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Howto/WorkingWithImages/CodeExamples

    v1 v4  
    1 == Code examples [STATUS: ONGOING] == 
    2 === Basics === 
    3 Including image tools library 
    4 {{{ 
    5 require_once SGL_CORE_DIR . '/Image.php'; 
    6 }}} 
    7 and creating image instance. 
    8 {{{ 
    9 $image = new SGL_Image(); 
    10 }}} 
    11 Note that constructor can accept 2 optional arguments i.e. ''image name'' and ''module name''. 
    12 {{{ 
    13 $image = new SGL_Image('riga.jpg'); 
    14 }}} 
    15 Image name is always set even if we omit it in constructor. In that case it will be autogenerated by 
    16 {{{ 
    17 SGL_Image#generateUniqueFileName() 
    18 }}} 
    19 Getting autogenerated image name after creating an instance. 
    20 {{{ 
    21 $image = new SGL_Image(); 
    22 $imageName = $image->getFileName(); 
    23 }}} 
    24 As mentioned above a ''module name'' can be passed as second optional argument to constructor. 
    25 {{{ 
    26 $image = new SGL_Image('riga.jpg', 'mymodule'); 
    27 }}} 
    28 Module name affects the path image is stored and looked for. By default, omitting the module name, save path is equal to ''SGL_UPLOAD_DIR'' constant value. In case module name is specified the path is as follows 
    29 {{{ 
    30 SGL_MOD_DIR . '/' . $moduleName . '/www/images' 
    31 }}} 
    32 Getting current image save path 
    33 {{{ 
    34 $image = new SGL_Image(); 
    35 $savePath = $image->getPath(); // $savePath equals to SGL_UPLOAD_DIR 
    36 }}} 
    37 or 
    38 {{{ 
    39 $image = new SGL_Image(null, 'media'); 
    40 $savePath = $image->getPath(); // $savePath equals to SGL_MOD_DIR/media/www/images 
    41 }}} 
    42 ''SGL_Image#getPath()'' is a ''special'' method, which can be called either statically or as instance call. The following example gives the same result as above one. 
    43 {{{ 
    44 $savePath = SGL_Image::getPath('media'); // $savePath equals to SGL_MOD_DIR/media/www/images 
    45 }}} 
    46 What for is an ability to specify image path other than ''SGL_UPLOAD_DIR''? In case of ''Media'' module it useless, because all images are shown through a ''wrapper'' i.e. ''!FileMgr#_cmd_previewMedia()'', thus user rights are preserved on it, because it is not possible to access ''SGL_UPLOAD_DIR'' folder directly (through HTTP request). If module name is specified symlinking is in action (''Media'', ''Ecomm'', ''Cms'' - these new modules use symlinking to store all their data at one place). So, if you need to build an image gallery module, which does not require setting user permissions on images, worth to try symlinking ability together with image tools. 
    47 There is one more special method (which can be called both as static or instance call) 
    48 {{{ 
    49 SGL_Image#getUrl() 
    50 }}} 
    51 which returns URL to image folder. 
    52 {{{ 
    53 $image = new SGL_Image(null, 'gallery'); 
    54 $url = $image->getUrl(); // $url equals to SGL_BASE_URL/gallery/images 
    55 }}} 
    56 {{{ 
    57 $url = SGL_Image::getUrl('gallery'); // $url equals to SGL_BASE_URL/gallery/images 
    58 }}} 
    59  
    60 Please note, if module name is not specified in constructor or, in case of static call, as argument for ''SGL_Image::getUrl()'', ''PEAR_Error'' object will be returned. 
    61 {{{ 
    62 $image = new SGL_Image(); 
    63 $url = $image->getUrl(); 
    64 if (PEAR::isError($url)) { 
    65     echo 'module name is not specified'; 
    66 
    67 }}} 
    68 === Initialization & dealing with configuration === 
    69  
    70 === Transformation === 
     1== Code examples == 
     2[[SubWiki(Howto/WorkingWithImages/CodeExamples)]]