I'm using ImageMagick to resize and create thumbnails. I am new to OSCommerce, MS@-MAX, and PHP. I have a working site where image modification is automated, but my coding is not finished, and this is my first MOD. Need some help! I'm looking for what I may be missing...
ImageMagick convienantly takes one number as input (in pixels) and scales image proportionately down so that width or height maximum is the number inputed. No need to do complex calculations or worry about landscape or portait image layouts... sweet
Basic process I',m using is:
Create the following folders to hold product images:
images/images_big (already installed, holds larger image that appears in pop-up window when clicking on display image).
images/images_display (the actual product displayed on website)
images/images_thumb (thumbnail images)
images/images_original (original image unmodified)
When the file is uploaded from Admin website, original uploaded image is run through ImageMagic 3 times to create an image for each folder. Original images is input to ImageMagick, and output is placed in its respective image folder. Then original full size image is moved to images_original. If copied to images_original, then original uploaded image has to be deleted when finished (I have not got that far yet). Here is my code in admin/includes/classes/upload.php (so far!)
Line 96, after:
Start MOD code here ->Code:function save() { global $messageStack; if (substr($this->destination, -1) != '/') $this->destination .= '/'; if (move_uploaded_file($this->file['tmp_name'], $this->destination . $this->filename)) { chmod($this->destination . $this->filename, $this->permissions);
Code:// MODIFY // COPY IMAGES TO DIFFERENT DIRECTORIES //////////////////// $originalImage = $this->destination . $this->filename; $copyImgBig = DIR_FS_DOCUMENT_ROOT . IMAGE_DIR_BIG . $this->filename; $copyImgDisplay = DIR_FS_DOCUMENT_ROOT . IMAGE_DIR_DISPLAY . $this->filename; $copyImgThumb = DIR_FS_DOCUMENT_ROOT . IMAGE_DIR_THUMB . $this->filename; $copyImgOriginal = DIR_FS_DOCUMENT_ROOT . IMAGE_DIR_ORIGINAL . $this->filename; chmod($originalImage, 0664); chgrp($originalImage, IMAGE_CONVERT_GROUP); //RESIZE PRODUCT IMAGES // Example // /usr/local/bin/convert -geometry 200 -quality 90 capture.jpg capture_dest.jpg $convert_big = IMAGEMAGICK_PATH . " -geometry " . IMAGE_SIZE_BIG . " -quality " . IMAGE_QUAL_BIG . " " . $originalImage . " " . $copyImgBig; system($convert_big); $convert_display = IMAGEMAGICK_PATH . " -geometry " . IMAGE_SIZE_DISPLAY . " -quality " . IMAGE_QUAL_DISPLAY . " " . $originalImage . " " . $copyImgDisplay; system($convert_display); $convert_thumb = IMAGEMAGICK_PATH . " -geometry " . IMAGE_SIZE_THUMB . " -quality " . IMAGE_QUAL_THUMB . " " . $originalImage . " " . $copyImgThumb; system($convert_thumb); chmod($copyImgBig, 0664); chmod($copyImgDisplay, 0664); chmod($copyImgThumb, 0664); chgrp($copyImgBig, IMAGE_CONVERT_GROUP); chgrp($copyImgDisplay, IMAGE_CONVERT_GROUP); chgrp($copyImgThumb, IMAGE_CONVERT_GROUP); // MOVE ORIGINAL FILE TO images_original if (!copy($originalImage, $copyImgOriginal)) {echo "failed to copy original " . $originalImage . $this->filename . " ...<br>\n";} // Delete original file uploaded // unlink($originalImage); // END MODIFY
And here are my declarations in admin/includes/local/configure.php
Code:// Image conversion sizes define('PHONE_NUMBER', '800-555-1212'); // Define catalog image directories for thumb, display, and large image save define('IMAGE_DIR_ORIGINAL', 'images/images_original/'); define('IMAGE_DIR_BIG', 'images/images_big/'); define('IMAGE_DIR_DISPLAY', 'images/images_display/'); define('IMAGE_DIR_THUMB', 'images/images_thumb/'); // Define root path to /gallery/ define('DIR_WS_GALLERY', HTTP_SERVER . DIR_WS_CATALOG); // Define URL to image folders define('IMAGE_URL_ORIGINAL', DIR_WS_GALLERY . 'images/images_original/'); define('IMAGE_URL_BIG', DIR_WS_GALLERY . 'images/images_big/'); define('IMAGE_URL_DISPLAY', DIR_WS_GALLERY . 'images/images_display/'); define('IMAGE_URL_THUMB', DIR_WS_GALLERY . 'images/images_thumb/'); // Path to ImageMagick define('IMAGEMAGICK_PATH', '/usr/bin/convert'); // New images group define('IMAGE_CONVERT_GROUP', 'web'); // Image conversion quality define('IMAGE_QUAL_BIG', '90'); define('IMAGE_QUAL_DISPLAY', '90'); define('IMAGE_QUAL_THUMB', '75'); // Image conversion sizes define('IMAGE_SIZE_BIG', '800'); define('IMAGE_SIZE_DISPLAY', '480'); define('IMAGE_SIZE_THUMB', '100');
One problem I am having is my declarions are not working in all template pages. I've had to add . 'images_thumb/' . (for each folder) to the image path where images are displayed. All images of different sizes are the same filename so all you have to do is modify the path in each location where an image is displayed. What I have not worked on is integration with MoPics, and deleting each image from each image directory when product and image is removed using admin site.
I am also working on adding an option to overlay copyright information on each image automaticly with ImageMagic as I am displaying artwork.
Cool tool for getting command line info for ImageMagick http://exeprod.com/developpement/resize/
Any help on this greatly appreciated.





LinkBack URL
About LinkBacks







Bookmarks