As has been discussed here http://www.oxid-esales.com/forum/showthread.php?p=75219#post75219, with the new OXID functionality to generate product images “on-the-fly” when the request for an image yields a 404 error, it has become virtually impossible to use the image loading from a separate server, to speed up loading.
The reason is, that you can’t copy the proper images to the correct server locations before they are needed, simply because they are not available until used.…
If you operate your own servers, then you can use a network file system to generate the images directly into the proper server directories, so this will be OK out of the box.
But if you are using a normal provider like most of us do, you are out of luck…
So, what to to, to regain this great feature?
The idea is:
after generating an image by the corresponding shop modules, transfer it automatically via FTP to the proper server and directory!
To achieve that, we have to modify the behaviour of some OXID modules.
These are:
“core\utils\getimg.php”
“core\oxpicturehandler.php”
and
“core\oxdynimggenerator.php”
The latter two can be appropriately modified by overload modules, “getimg.php” however needs to be changed directly.
What has to be done specifically?
(Necessary changed and additional files are included in the archive attached.)
When creating image URLs, OXID checks in the “oxpicturehandler => getAltImageUrl”-function, if an alternate image server address has been defined.
If yes, this one is used as base for the image URL, if no, the local server is used for the image URL.
As the new concept relies on the images beeing available on the alternate server, we can not use the standard OXID behaviour to just substitute the alternative image server in the image URL (if it is defined), as the image is not available on the image server the first time it is referenced!
So we have to make sure, that an image is available on the server, before we decide to use it.
As querying the image server every time for image availabilty would slow down processing, we use the availability of a local image as indicator, that an image is also available on the server.
(Optionally you can define, that the locally generated images shall be truncated to zero length after transfer to save local space.
It might however be advisable to leave them as they are, to be able to retransfer them to the server, if necessary.)
As the images are only transferred via FTP to the image server after they have been created “on-the-fly”, we have to delete/rename the local “generated” directory in the “pictures” directory, to get the process started properly!!!
If an error should occur with the FTP uploading, an entry is made in the file “log/ftp_alt_image_xfer.log”;
This functionality has been tested with OXID 4.5.7, no idea, if it works with previous versions…
The changes in “core\utils\getimg.php” just make sure, that our new image generating process with FTP transfer is used instead of the standard one (“oxdynimggenerator => outputImage”-function).
This new process is located in module “modules\powertemplate\pt_oxdynimggenerator\pt_oxdynimggenerator.php”.
As mentioned before, we can not use the external image server URL just because it is defined any more, so we need to modify some shop-methods which construct image URLs.
This happens in “modules\powertemplate\pt_oxpicturehandler\pt_oxpicturehandler.php”.
Important:
this automatic FTP transfer process only(!) works for images generated by the shop, as we hook into that process for the automatic image transfer.
This means, that you must(!) transfer other content in the “pictures” directory manually(!) via FTP to make them available to the shop!
(E.g.: directories “media”, “promo”, “wysiwigpro” aso., i.e. everything but the “master” and “generated” directories!)
How do you tell the software to use this functionality?
Make a backup copy of the shop!
Copy the “core” and “modules” directories of the attached archive to the shop root.
Then you need some additional parameters in “config.inc.php”:
$this->sAltImageUrl='http://www.my_image_server.de/oxid_images/';
$this->sSSLAltImageUrl='https://www.my_image_server.de/oxid_images/';
$this->sFTPImageDir='oxid_images';
$this->sFTPImageServer='my_image_server.de';
$this->sFTPImageUser='user';
$this->sFTPImagePassword='password';
$this->bTruncateLocalImage=false; //Truncate local image to zero length if true.
Finally, the following additional entry has to be made in the admin/modules area:
oxpicturehandler=>powertemplate/pt_oxpicturehandler/pt_oxpicturehandler
[B]Use at your own risk only, no warranties and support whatsoever will be provided…
[COLOR=Blue]Never ever use it directly in a live shop, but only in a test environment!!![/B][/COLOR]