VirtueMart Forum

VirtueMart Dev/Coding Central: VM1 (old version) => Quality & Testing VirtueMart 1.1.x => Virtuemart 1.1 Development (Archiv) => Q&T Resolved => Topic started by: Pixell on February 13, 2009, 16:49:18 pm

Title: [FIXED] Image and thumb stored in the same folder + additional thumb in resized
Post by: Pixell on February 13, 2009, 16:49:18 pm
I thought I was seeing double but when I looked in the folder where the full image is stored I could even see a copy of this file but a smaller version (a thumb).
And if I go to the resized folder I could see that there is an additional file there.
So there is totaly of three files.

I saw the problem on the site I was working on, so I then installed a fresh Joomla Version 1.5.9 and Virtuemart 1.1.3 just to confirm that I didn't have messed it up somewhere with the site I was working on.

So I added a new dummy product with a dummy image on the new fresh installation.
The result was the same! It had now created:

/components/com_virtuemart/shop_image/product/

/components/com_virtuemart/shop_image/product/resized/

Can somebody else confirm this?
Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: Jan on May 07, 2009, 14:40:16 pm
Thats a strange situation.
I think i have the same problem...
I also have some extra files... :-(
Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: salobon on June 01, 2009, 08:08:35 am
I have similar problem.
I use V 1.1.3 J1.5.10 and every time I upload image from product edit panel - it created two images in each folder!!!
I looked up the code and figured the problem!
need to modify file:
Code: [Select]
/administrator/components/com_virtuemart/classes/imageTools.class.phpI have modified it last night and it works better but not perfect.
here's the contents that I have changed:
this code line69:
Code: [Select]
if( @$d[$tmp_field_name.'_action'] == 'auto_resize' ) {changed with this:
Code: [Select]
if(( @$d[$tmp_field_name.'_action'] == 'auto_resize' )&&(strstr($field_name, "thumb" ))) {line 153-156 was
Code: [Select]
}
}
}
}
add this
Code: [Select]
}
}
}
return true;
}

!!!!!!!!!!!!!!!!! code above corrects double creation

this part 186-198 commented:
Code: [Select]
// if( PSHOP_IMG_RESIZE_ENABLE=="1" && $image_type == "thumbnail image") {
// $pathinfo = pathinfo( $delete );
// isset($pathinfo["dirname"]) or $pathinfo["dirname"] = "";
// isset($pathinfo["extension"]) or $pathinfo["extension"] = "";
// $filehash = basename( $delete, ".".$pathinfo["extension"] );
// $resizedfilename = $pathinfo["dirname"]."/resized/".$filehash."_".PSHOP_IMG_WIDTH."x".PSHOP_IMG_HEIGHT.".".$pathinfo["extension"];
//
//                 $d["image_commands"][] = array( 'command' => 'unlink',
//         'param1' => $resizedfilename
//         );
// $vmLogger->debug( 'Preparing: delete resized thumbnail '.$resizedfilename );
//
// }
this will prevent messed up queries to database that will pass in image_control array
line 248
Code: [Select]
$delete = str_replace( "\\", "/", realpath($path)."/".$curr_file);change with this:
Code: [Select]
$delete = str_replace( "\\", "/", realpath($path)."/".$curr_file);
and also comment this:
Code: [Select]
// if( PSHOP_IMG_RESIZE_ENABLE=="1" && $image_type == "thumbnail image") {
// $pathinfo = pathinfo( $delete );
// $filehash = basename( $delete, ".".$pathinfo["extension"] );
// $resizedfilename = $pathinfo["dirname"]."/resized/".$filehash."_".PSHOP_IMG_WIDTH."x".PSHOP_IMG_HEIGHT.".".$pathinfo["extension"];
//
//           $d["image_commands"][] = array( 'command' => 'unlink',
//         'param1' => $resizedfilename
//         );
// $vmLogger->debug( 'Preparing: delete resized thumbnail '.$resizedfilename );

// }
last section is commented for same reason as previous - was passing unnecessary and incorrect commands to database query.



Now it work perfect if you upload image and use auto-create thumb.
BUT it still creates unwanted thumb when you upload full image and select "none" for thumb.
I'm ready to answer any questions.

Developer Team,
if you could give me some rights to fix bugs on tracker, I could do some... I know Javascript and PHP, self-taught and ready to help.
I have posted a minor bug ([2638] (http://dev.virtuemart.net/cb/issue/2638)) at tracker already and would easily fix it myself if I had rights.
Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: aravot on June 01, 2009, 08:28:45 am
@salobon, if you want to join the development team please see http://forum.virtuemart.net/index.php?topic=20780.msg95533#msg95533
Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: salobon on June 02, 2009, 03:06:18 am
just a quick followup to this problem
If you turn off dynamic thumbnail creation in global config it will stop creating extra thumb in /resize folder.

I have modified file even more efficiently... if anyone id interested I can post a full code here...
Almost 36 lines of code was commented off...
Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: doorknob on June 04, 2009, 14:29:25 pm
If anybody is interested, I wrote this and added it to the admin menu in the backend to remove unwanted image files
Code: [Select]
<?php
if( !defined'_VALID_MOS' ) && !defined'_JEXEC' )) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
/**
 * Removes image files in the product, category, vendor and merchant folders that are not referenced in the database
 */
mm_showMyFileName__FILE__ );

$show_deletions false;
if( 
$show_deletions ) {
echo "<b>Deleted Files</b><br />";
}
$count 0;

// Create database object
$db = new ps_DB;

$allowed_files = array( 'index.html''index.htm' );

// Product full & thumbnail images
// Prepare an array of valid file names (thumbnails include sub-directory in file name)
$db->query"SELECT product_full_image FROM #__{vm}_product UNION SELECT product_thumb_image FROM #__{vm}_product" );
$image_files $db->loadResultArray();

// Get the list of current files in the main directory
$dir_name JPATH_ROOT.DS.'components'.DS.'com_virtuemart'.DS.'shop_image'.DS.'product';
if( 
is_dir($dir_name) ) {
$file_names scandir$dir_name );
foreach( $file_names as $file_name ) {
$path_name $dir_name.DS.$file_name;
if( is_file$path_name ) && !in_arraystrtolower$file_name ), $allowed_files ) ) {
// Check whether the file is referenced in the product table
if( !in_array$file_name$image_files ) ) {
if( $show_deletions ) {
echo $path_name.'<br />';
}
unlink$path_name );
$count++;
}
}
}
}
// Get the list of current files in the thumbnail sub- directory
$dir_name $dir_name.DS.'resized';
if( 
is_dir($dir_name) ) {
$file_names scandir$dir_name );
foreach( $file_names as $file_name ) {
$path_name $dir_name.DS.$file_name;
if( is_file$path_name ) && !in_arraystrtolower$file_name ), $allowed_files ) ) {
// Check whether the file is referenced in the product table
// Note: '/' is used rather than DS because it must exactly match the value stored by VM
if( !in_array'resized/'.$file_name$image_files ) ) {
if( $show_deletions ) {
echo $path_name.'<br />';
}
unlink$path_name );
$count++;
}
}
}
}

// Category full & thumbnail images
// Prepare an array of valid file names (thumbnails include sub-directory in file name)
$db->query"SELECT category_full_image FROM #__{vm}_category UNION SELECT category_thumb_image FROM #__{vm}_category" );
$image_files $db->loadResultArray();

// Get the list of current files in the main directory
$dir_name JPATH_ROOT.DS.'components'.DS.'com_virtuemart'.DS.'shop_image'.DS.'category';
if( 
is_dir($dir_name) ) {
$file_names scandir$dir_name );
foreach( $file_names as $file_name ) {
$path_name $dir_name.DS.$file_name;
if( is_file$path_name ) && !in_arraystrtolower$file_name ), $allowed_files ) ) {
// Check whether the file is referenced in the category table
if( !in_array$file_name$image_files ) ) {
if( $show_deletions ) {
echo $path_name.'<br />';
}
unlink$path_name );
$count++;
}
}
}
}
// Get the list of current files in the thumbnail sub- directory
$dir_name $dir_name.DS.'resized';
if( 
is_dir($dir_name) ) {
$file_names scandir$dir_name );
foreach( $file_names as $file_name ) {
$path_name $dir_name.DS.$file_name;
if( is_file$path_name ) && !in_arraystrtolower$file_name ), $allowed_files ) ) {
// Check whether the file is referenced in the category table
// Note: '/' is used rather than DS because it must exactly match the value stored by VM
if( !in_array'resized/'.$file_name$image_files ) ) {
if( $show_deletions ) {
echo $path_name.'<br />';
}
unlink$path_name );
$count++;
}
}
}
}

// Vendor full & thumbnail images
// Prepare an array of valid file names (vendor thumbnails in main directory)
$db->query"SELECT vendor_full_image FROM #__{vm}_vendor UNION SELECT vendor_thumb_image FROM #__{vm}_vendor" );
$image_files $db->loadResultArray();

// Get the list of current files in the main directory
$dir_name JPATH_ROOT.DS.'components'.DS.'com_virtuemart'.DS.'shop_image'.DS.'vendor';
if( 
is_dir($dir_name) ) {
$file_names scandir$dir_name );
foreach( $file_names as $file_name ) {
$path_name $dir_name.DS.$file_name;
if( is_file$path_name ) && !in_arraystrtolower$file_name ), $allowed_files ) ) {
// Check whether the file is referenced in the vendor table
if( !in_array$file_name$image_files ) ) {
if( $show_deletions ) {
echo $path_name.'<br />';
}
unlink$path_name );
$count++;
}
}
}
}

global 
$vmLogger;
$vmLogger->info"Image File Check Completed - $count Files Deleted" );

// Create the object and print a form heading
$formObj = &new formFactory'Check Image Files' );
$formObj->startForm();
?>

<table class="adminform">
  <tbody>
<tr>
      <td>
          <input type="submit" class="button" value="Click to Continue" style="width:100%;font-size:200%;" />
      </td>
  </tbody>
</table>
<?php
$modulename 
'store';
$pagename 'index';
$option 'com_virtuemart';
$formObj->finishForm''$modulename.'.'.$pagename$option );
?>

Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: Pixell on June 08, 2009, 14:56:13 pm
Doorknob... Where do I put your code? Which file to modify.
This is very good to have in the backend menu.
Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: doorknob on June 09, 2009, 03:51:16 am
This is a whole program.
I called it admin.check_vm_images.php and linked it to the vm admin menu by modifying header.php and adding the following code:
Code: [Select]
<li class="item-smenu vmicon vmicon-16-content">
<a href="<?php $sess->purl($_SERVER['PHP_SELF']."?pshop_mode=admin&amp;page=admin.check_vm_images&amp;module_id=".$module_id?>">Check Images &amp; Thumbnails</a>
</li>
Phil
Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: Pixell on June 09, 2009, 10:34:00 am
Thank you!
Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: andrey_fix on June 24, 2009, 09:06:10 am
how to make virtuemart 1.0.15 ?
sorry for my english.
Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: ABunning on October 16, 2009, 15:41:43 pm
@Doorknob:
This is brilliant!
Works so well and should be a permanent addon to vitruemart!

Only question: will this work for sub-folders?
Reason I ask is that I'm trying to setup a sub folder for each manufacturer with the appropriate pictures there.

Thanks,
   Andrew
Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: darasso1 on October 31, 2009, 21:07:36 pm
salobon
thx for your remarks regarding the thumb creation process.
I have implemented your change:

Code: [Select]
if(( @$d[$tmp_field_name.'_action'] == 'auto_resize' )&&(strstr($field_name, "thumb" ))) {

and it works great.... no additional thumb created.
I knew the reason for this but I couldnt figure out the code solution.


I am currently working on turning the VM store into multivendor place and I was also struggling with  imageTools.class.php.

Regards,
Dariusz :)
www.piekloniebo.pl (http://www.piekloniebo.pl)

Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: bonbin on March 03, 2011, 20:44:28 pm
hello everyone, im using virtuemart 1.1.3
im facing the same issue with thread starter
but the worst one is.. everytime i remove the products in virtuemart
the thumbnail images are still on that both of folder, which mean the only image removed was the original images

any one can help me? its kinda hard for me to removing manual one by one from the folder since the product on my site is more than a thousand and i need to remove a hundred product every week :(
Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: zanardi on March 04, 2011, 00:20:31 am
The issue about a duplicate resized image has been fixed in SVN and will be released in the upcoming 1.1.8 version.
Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: bonbin on March 04, 2011, 08:21:20 am
hi zanardi,

thx for ur information
how about the both thumbnail images are didnt being deleted when im deleting the products on virtuemart ?
Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: zanardi on March 05, 2011, 13:38:40 pm
@bonbin:
if you are in the mood to test, strictly on a NON PRODUCTION environment, a "BETA" 1.1.8 package is ready. I repeat: this is a BETA package, which still need some basic testing, and should NOT used on live shop.

If you still want it, you can download it from

http://dev.virtuemart.net/issues/308
Title: Re: Image and thumb stored in the same folder + additional thumb in resized folder
Post by: diastasi on April 08, 2011, 10:45:16 am
CAUTION!!
The issue is fixed in 1.1.8.
If anyone make the changes in the first post please replace with the original file, because NO THUMBNAILS WILL BE CREATED if you keep the changes.!!!