Author Topic: [FIXED] Image and thumb stored in the same folder + additional thumb in resized  (Read 22588 times)

Pixell

  • Beginner
  • *
  • Posts: 26
    • Pixelic.com
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/
  • Dummy_Product_499592123f923.jpg (size: 90x79px)
  • Dummy_Product_499592124ded9.jpg (size: 746x663px)

/components/com_virtuemart/shop_image/product/resized/
  • Dummy_Product_499592123fb2c_90x90.jpg (size: 90x79px)

Can somebody else confirm this?

Jan

  • Beginner
  • *
  • Posts: 17
Thats a strange situation.
I think i have the same problem...
I also have some extra files... :-(

salobon

  • Jr. Member
  • **
  • Posts: 317
    • Herbolution
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]) at tracker already and would easily fix it myself if I had rights.


salobon

  • Jr. Member
  • **
  • Posts: 317
    • Herbolution
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...

doorknob

  • Jr. Member
  • **
  • Posts: 151
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 );
?>


Pixell

  • Beginner
  • *
  • Posts: 26
    • Pixelic.com
Doorknob... Where do I put your code? Which file to modify.
This is very good to have in the backend menu.

doorknob

  • Jr. Member
  • **
  • Posts: 151
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

Pixell

  • Beginner
  • *
  • Posts: 26
    • Pixelic.com
Thank you!

andrey_fix

  • Beginner
  • *
  • Posts: 1
how to make virtuemart 1.0.15 ?
sorry for my english.

ABunning

  • Beginner
  • *
  • Posts: 8
    • ToolForce
@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

darasso1

  • Beginner
  • *
  • Posts: 38
    • piekloniebo.pl - kolczyki, klipsy, bransoletki
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

www.piekloniebo.pl -
handmade jewelry store - take a look!!! - kolczyki, klipsy, bransoletki

bonbin

  • Beginner
  • *
  • Posts: 25
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 :(

zanardi

  • Contributing Developer
  • Full Member
  • *
  • Posts: 878
    • GiBiLogic
The issue about a duplicate resized image has been fixed in SVN and will be released in the upcoming 1.1.8 version.
--
Francesco (zanardi)
http://extensions.gibilogic.com
@gibilogic on Twitter

bonbin

  • Beginner
  • *
  • Posts: 25
hi zanardi,

thx for ur information
how about the both thumbnail images are didnt being deleted when im deleting the products on virtuemart ?