|
Img2
0.1
|
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 Img2 * | getInstance () |
| A shared Img2 instance, should be used instead of 'new Img2()' to minimize the database connection overhead. | |
Friends | |
| int | main (int, char **) |
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);
| 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.
| fileId | Unique identifier of the file. |
| _id | This 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.
| fileId | Unique identifier of the file. |
| maxWidth | The width the scaled image should fit. |
| maxHeight | The height the scaled image should fit. |
| humanReadableName | Prefix 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).
| fileId | Unique identifier of the file. |
| maxWidth | The width the scaled image should fit. |
| maxHeight | The height the scaled image should fit. |
| watermarkName | Unique identifier of the watermark. |
| watermarkPath | Watermark location in the filesystem. |
| humanReadableName | Prefix 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.
| fileId | Unique identifier of the file. |
| humanReadableName | File name for the browser. |
| string Img2::hi | ( | ) |
Test if basic database operations work.
| 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.
| fileId | Unique 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.
| fileId | Unique identifier of the file. |
| path | Local filesystem location of the file contents. |
| oDb | The name of the MySQL database were the file owning object is located. |
| oTable | The table hosting the file owning object. |
| oIdField | The unique identifier field in the oTable. |
| oId | The value of the oIdField which identifies the object which owns the file. |
1.7.6.1