PDA

View Full Version : ImageMagick and images - its all about automation!



carver6
01-12-2004, 12:43 PM
I'm using ImageMagick to resize and create thumbnails. I am new to OSCommerce, [email protected], 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:


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);

Start MOD code here ->



// 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


// 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.

Anonymous
01-19-2004, 11:44 PM
Its not all workin / finished, but you can see the image modified in most places here. When I first installed MS2 Max it appeared that thumbnail images were fullsize images that were resized in the img tags. So a page with 20 thumbnails was like 2400Kb in images instead of 80 Kb. HUGE difference. Also, with medium size images, can display larger image on product page. I don't want to see a thumbnail on the product page. I want to "see" the product! http://artgalleryscene.com/gallery/index.php

Anonymous
02-04-2004, 04:39 AM
thanks for this little tip, I have now saved myself an awful lot of bother creating multiple images for each product. I used the basics of your code to create both thumbnails and larger images so that MoPics can display the larger image from the (click to enlarge) link. Thanks.

Anonymous
02-16-2004, 12:13 PM
so has anyone else tried this one.?

carver6
07-18-2004, 12:20 AM
Its running at htt://www.dancingspiritsgallery.com/

pthurmond
08-02-2004, 10:27 AM
Does anyone know if you can just install the convert utility into a directory on your server instead of the entire program and still use it? Reason being is my host provider refuses to install ImageMagick on the server for me (which is pissing me off) and I want to find an alternate way to run it. Preferably a PHP version of it.

Anonymous
08-02-2004, 04:40 PM
Can use mogrify, which is part of the ImageMagic package. It will eliminate having to create temp images. It will overwrite itself. Regarding your hosting... get a virtual server and install what ever you want! If they won't let you run the apps you need, the response is "later"! (buh bye...)

pthurmond
08-03-2004, 01:19 PM
Ok, so the main question is, is it something that has an install as unattached to the server as oscommerce (folder-based install) or does the actual server have to have the program installed as an RPM or something. I am trying to just use the convert utility without doing a full and literal install on the server at the OS level. I want this install to be along the lines of PostNuke, PHPNuke, OSCommerce, Xoops, etc.

pthurmond
08-03-2004, 01:22 PM
I would drop this provider but I don't know of any other provider that offers 9GB of space with CPANEL controls, ftp, unlimited e-mail addresses, 20 SQL databases, and 35GB traffic for $12 per month.

If you know of a provider that can beat that then by all means let me know.

hobbyhen
09-05-2004, 09:11 PM
So if I want to use this, besides copying this guy's code from above, what do I need to do with the "image_thumbs" directory he was speaking of?

Anybody know when this can be released as a mod?

hobbyhen
09-07-2004, 05:09 PM
I tried implementing this system and it didn't populate the 3 separate directories with iimages. I hope this becomes a contribution very very soon. In fact, i'd even pay for it!