Img2  0.1
Public Member Functions | Static Public Member Functions | Friends
Img2 Class Reference

Keep files in a distributed database. More...

#include Img2.h>

Public Member Functions

string hi ()
 Test if basic database operations work.
void storeFile (string fileId, string path, string oDb, string oTable, string oIdField, string oId)
 Save file into the distributed database.
string getUrl (string fileId, string humanReadableName)
 URL to the stored file contents.
string getScaleUrlV0 (string fileId, int maxWidth, int maxHeight, string humanReadableName)
 URL to the scaled copy of the file.
string getScaleUrlV1 (string fileId, int maxWidth, int maxHeight, string watermarkName, string watermarkPath, string humanReadableName)
 URL to the scaled copy of the file.
void deleteFile (string fileId, string *_id)
 Remove the file from the database.
bool optionalHaveFile (string fileId)
 Checks if the distributed storage still have this file.

Static Public Member Functions

static Img2getInstance ()
 A shared Img2 instance, should be used instead of 'new Img2()' to minimize the database connection overhead.

Friends

int main (int, char **)

Detailed Description

Keep files in a distributed database.

Usage example:

      include ('img2.php');
      $img2 = Img2::getInstance();
      $img2->storeFile ($fileId, $filePath, $db, $table, $rowIdField, $rowId);
      $url = $img2->getUrl ($fileId, $humanReadableName);
      $scaledUrl = $img2->getScaleUrlV0 ($fileId, 100, 100, $humanReadableName);
      $watermarkName = "/banner/foto_stamp.png";
      $watermarkPath = "/home/grank/mercatos.ru/public_html/banner/foto_stamp.png";
      $stampedUrl = $img2->getScaleUrlV1 ($fileId, 300, 300, $watermarkName, $watermarkPath, $humanReadableName);
    

Member Function Documentation

void Img2::deleteFile ( string  fileId,
string *  _id 
)

Remove the file from the database.

The scaled images produced by getScaleUrlV0 and getScaleUrlV1 are removed as well.

Parameters:
fileIdUnique identifier of the file.
_idThis is an optional parameter, you don't have to use it from PHP!
If you already have a Tiger hash of the fileId you can save some time by passing it along.
string Img2::getScaleUrlV0 ( string  fileId,
int  maxWidth,
int  maxHeight,
string  humanReadableName 
)

URL to the scaled copy of the file.

If scaled copy does not exists then it is created automatically when the URL is used for the first time.

Parameters:
fileIdUnique identifier of the file.
maxWidthThe width the scaled image should fit.
maxHeightThe height the scaled image should fit.
humanReadableNamePrefix of the file name for the browser.
The full file name is: "{humanReadableName}_{width}x{height}.jpg".
string Img2::getScaleUrlV1 ( string  fileId,
int  maxWidth,
int  maxHeight,
string  watermarkName,
string  watermarkPath,
string  humanReadableName 
)

URL to the scaled copy of the file.

If scaled copy does not exists then it is created automatically when the URL is used for the first time.

The image is only scaled down, not up. That is, if the size of the original image is smaller than maxWidth x maxHeight, then the original image size is preserved.

This method will also check if the watermark file is present in the database and will upload it there if it isn't (or if the size differs).

Parameters:
fileIdUnique identifier of the file.
maxWidthThe width the scaled image should fit.
maxHeightThe height the scaled image should fit.
watermarkNameUnique identifier of the watermark.
watermarkPathWatermark location in the filesystem.
humanReadableNamePrefix of the file name for the browser.
The full file name is: "{humanReadableName}_{width}x{height}.jpg".
string Img2::getUrl ( string  fileId,
string  humanReadableName 
)

URL to the stored file contents.

Note: This method does not interact with the distributed database.

Parameters:
fileIdUnique identifier of the file.
humanReadableNameFile name for the browser.
string Img2::hi ( )

Test if basic database operations work.

See http://mercatos.ru/test_img.php

bool Img2::optionalHaveFile ( string  fileId)

Checks if the distributed storage still have this file.

Note: In the future, when the distributed storage has been sufficiently tested and all files have been transferred there, we expect this method to do nothing and always return true. This is why this method is called an "optional" haveFile.

Parameters:
fileIdUnique identifier of the file.
void Img2::storeFile ( string  fileId,
string  path,
string  oDb,
string  oTable,
string  oIdField,
string  oId 
)

Save file into the distributed database.

If the file is an image in a popular format then this method will try to detect its size and save it together with the image contents.

If the fileId already exists in the distributed database then the method will invoke deleteFile before proceeding.

Parameters:
fileIdUnique identifier of the file.
pathLocal filesystem location of the file contents.
oDbThe name of the MySQL database were the file owning object is located.
oTableThe table hosting the file owning object.
oIdFieldThe unique identifier field in the oTable.
oIdThe value of the oIdField which identifies the object which owns the file.

The documentation for this class was generated from the following file:
 All Data Structures Functions