Index: openacs-4/packages/ecommerce/tcl/resource-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/tcl/resource-procs.tcl,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/ecommerce/tcl/resource-procs.tcl 27 Aug 2008 12:46:12 -0000 1.3 +++ openacs-4/packages/ecommerce/tcl/resource-procs.tcl 27 Aug 2008 22:48:07 -0000 1.4 @@ -14,9 +14,11 @@ -tmp_filename {-product_name ""} {-dirname ""} + {-file_extension ""} } { This proc imports a product image and creates the thumbnail and product image sized versions of the image. - The original image referenced by tmp_filename is not changed. + The original image referenced by tmp_filename is not changed. + file_extension is required when importing an image from a form for example, since the tmp_filename will not indicate file_extension. Product name should only be supplied when importing an image for a new product. For updating existing products, leave product_name blank. @@ -35,14 +37,16 @@ set success 1 set file_extension_actual [file extension $tmp_filename] set file_ext_lower [string tolower $file_extension_actual] - + if { ![string match {.[jg][pi][gf]} $file_ext_lower] } { + set file_ext_lower [string tolower $file_extension] + } if { $file_ext_lower eq ".jpg" || $file_ext_lower eq ".gif" } { # get the directory name set resource_path [ecommerce::resource::resource_path -product_id $product_id -product_name $product_name -dirname $dirname] # permanent full size filename - set perm_filename [file join $resource_path "product.${file_ext_lower}"] + set perm_filename [file join $resource_path "product${file_ext_lower}"] # Find and remove any previously saved product image # There should be no more than 1 previous file, unless another was added directly.. @@ -57,21 +61,21 @@ # use file copy http://www.mail-archive.com/naviserver-devel@lists.sourceforge.net/msg00685.html if [catch {file copy $tmp_filename $perm_filename} ] { # when importing, there may be permissions issues - ns_log Notice "ecommerce::resource::make_product_images: unable to copy $tmp_filename to $perm_filename" + ns_log Notice "ecommerce::resource::make_product_images: unable to: file copy $tmp_filename $perm_filename" set success 0 } # create thumbnails and standardized product image if { $success } { - set success [ecommerce::resource::resize_image -type Thumbnail -filename $perm_filename -dest_dir $resource_path] + set success [ecommerce::resource::resize_image -type Thumbnail -filename $perm_filename] } if { $success } { - set success [ecommerce::resource::resize_image -type ProductImage -filename $perm_filename -dest_dir $resource_path] + set success [ecommerce::resource::resize_image -type ProductImage -filename $perm_filename] } } else { # flag a soft error, we do not want to ad_return_complaint because this proc may be bulk uploading product images set success 0 - ns_log Notice "ecommerce::resource::make_product_images: file extension ${file_extension_actuial} not supported, -product_id ${product_id}" + ns_log Notice "ecommerce::resource::make_product_images: file extension ${file_ext_lower} not supported, -product_id ${product_id}" } if { $success } { @@ -89,7 +93,7 @@ } { if { $type eq "Thumbnail" || $type eq "ProductImage" } { set success 1 - # -dest_dir is now calculated automatically. + # dest_dir is now calculated automatically. set dest_dir [file dirname $filename] # get dimensions set use_both_param_dimensions [parameter::get -parameter "${type}SizeOuterlimits"] @@ -119,14 +123,16 @@ if { [file exists $filename] } { if {![string equal "" $convert] && [file exists $convert]} { if [catch {exec $convert -geometry $convert_dimensions -comment \"$image_comment\" $filename $new_filename} errmsg ] { - ns_log Notice "ecommerce::resource::resize_image An error occurred while converting a product image: $errmsg" + ns_log Notice "ecommerce::resource::resize_image An error occurred while attempting '$convert -geometry $convert_dimensions -comment \"$image_comment\" $filename $new_filename': $errmsg" set success 0 } } else { - ad_return_complaint 1 { - ImageMagick's convert utility for - image thumbnail creation seems unavailable. Please reconfigure this subsystem before - uploading pictures. + ns_log Error "ecommerce::resource::resize_image Check convert path parameter, convert not found at $convert" + set success 0 +# ad_return_complaint 1 { + # ImageMagick's convert utility for + # image thumbnail creation seems unavailable. Please reconfigure this subsystem before + # uploading pictures. } } } else { Index: openacs-4/packages/ecommerce/www/admin/products/edit-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/edit-2.tcl,v diff -u -N -r1.13 -r1.14 --- openacs-4/packages/ecommerce/www/admin/products/edit-2.tcl 14 Aug 2008 10:51:32 -0000 1.13 +++ openacs-4/packages/ecommerce/www/admin/products/edit-2.tcl 27 Aug 2008 22:48:06 -0000 1.14 @@ -127,26 +127,36 @@ # Get the directory where dirname is stored set dirname [db_string dirname_select "select dirname from ec_products where product_id=:product_id"] -set subdirectory [ec_product_file_directory $product_id] -set full_dirname "[ec_data_directory][ec_product_directory]$subdirectory/$dirname" +set full_dirname [file join [ec_data_directory] [ec_product_directory] [ec_product_file_directory $product_id] $dirname] # if an image file has been specified, upload it into the # directory that was just created and make a thumbnail (using # dimensions specified in parameters/whatever.ini) if { [exists_and_not_null upload_file] } { + # so that we'll know if it's a gif or a jpg + set file_extension [file extension $upload_file] + # tmp file will be deleted when the thread ends - set tmp_filename ${upload_file.tmpfile} + set tmp_filename ${upload_file.tmpfile} - # copy image & create thumbnails - # thumbnails are all jpg files + # copies this temp file into a permanent file +# set perm_filename [file join $full_dirname "product${file_extension}"] + - ecommerce::resource::make_product_images \ - -file_extension [file extension $upload_file] \ + + # import, copy image & create thumbnails + # thumbnails are all jpg files + ns_log Notice $upload_file + set upload_status [ecommerce::resource::make_product_images \ -product_id $product_id \ - -tmp_filename ${upload_file.tmpfile} + -tmp_filename ${upload_file.tmpfile} \ + -file_extension $file_extension] + if { $upload_status == 0 } { + ad_return_complaint 1 "
  • There was an error when trying to upload the new product image. Check the server logs if this message persists.
  • " + } } set dirname [ecommerce::resource::dirname -product_id $product_id -product_name $product_name]