Forums / Templates, Stylesheets, Page Layout / Multiple Images for One Listing Questions

Multiple Images for One Listing Questions

Locked

Views: 9,727

Results 21 to 40 of 48
This thread is locked. New replies are disabled.
16 Oct 2007, 8:06 PM
#21
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Multiple Images for One Listing Questions

// check for a medium image else use small
$products_image_medium = $products_image_base . IMAGE_SUFFIX_MEDIUM . $products_image_extension;
if (file_exists(DIR_WS_IMAGES . 'medium/' . $products_image_medium)) {
$base_image = DIR_WS_IMAGES . 'medium/' . $products_image_medium;
}
$thumb_slashes = zen_image($base_image, addslashes($products_name), MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT);
$thumb_regular = zen_image($base_image, $products_name, MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT);

I used to code years ago working with 8bit machines...so I tried reading this...cuz I have NO real experience with PHP....

and I found what I thought was an issue (in green).

So I changed it to read:

// check for a medium image else use small
$products_image_medium = $products_image_base . $products_image_extension . IMAGE_SUFFIX_MEDIUM ;
if (file_exists(DIR_WS_IMAGES . 'medium/' . $products_image_medium)) {
$base_image = DIR_WS_IMAGES . 'medium/' . $products_image_medium;
}
$thumb_slashes = zen_image($base_image, addslashes($products_name), MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT);
$thumb_regular = zen_image($base_image, $products_name, MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT);

and now it works!!!!!!!!!

Hooray!!!!!!!!!!!!
= )

Thanks Dr. Byte!!!

16 Oct 2007, 10:23 PM
#22
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Re: Multiple Images for One Listing Questions

I didn't fix the problem after all....... :no::no::no:

lol

I used test images with the same color background as the background of the page...and only marked them with a "1" and "2" corresponding to additional images '1' and '2'.....

So I thought the additional images were displaying MEDIUM files, but........I went out and came back to working on this.............and it seems that I didn't realize the numerals were written so big. lol They were just my thumbnail-sized photos displaying as the additional photos.

So...

I haven't solved anything. :(

Anyone reading this who knows what I can do to correct this issue, please let me know.

Thank you...

PS --I thought 'Image Suffix Medium' in uppercase meant it was a constant....
meaning it referred to whatever medium-sized files are set to be called in admin.

So I thought that '$products_image_extension' referred to the additional part of the
string that comprises a photo file's name if it is an additional image. (eg 01, 02, whatever)

So....that's why I thought it was reversed. Still confused!!!!!!!!!!!!

17 Oct 2007, 11:54 AM
#23
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Re: Multiple Images for One Listing Questions

I STILL can't seem to get MEDIUM photos to display as additionals.

I read the additional photos PHP file, and I see that I was way off in the change that I made. I read the WHOLE file this time, and I realize that I was clueless. Now Im a *little *less clueless, but not much.

But still cant figure out whats up.....................!!

Any ideas would be GREAT..........!

thank u kindly!

18 Oct 2007, 4:15 PM
#24
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Re: Multiple Images for One Listing Questions

Donn:

I STILL can't seem to get MEDIUM photos to display as additionals.

I read the additional photos PHP file, and I see that I was way off in the change that I made. I read the WHOLE file this time, and I realize that I was clueless. Now Im a *little *less clueless, but not much.

But still cant figure out whats up.....................!!

Any ideas would be GREAT..........!

thank u kindly!

UPDATE.........still no success with this.

:blink::blink::blink::blink::blink:

To rehash it briefly:

I need the additional photos to display as MEDIUM instead of the default thumbnail size.

The script provided above in this thread by Dr. Byte doesn't work for some reason.

The additional photos display in MEDIUM size....OK.........

But they are ALL simply IMAGE_LRG and not the IMAGE_LRG_XX array of additional photos.

If I click for larger photo, tho, it WILL dispaly the correct LARGE photos........

Again.........I DO need help....Im stuck......

Thank you all for the help so far....this is making ZC a GREAT experience...I dont have the background to figure this all out on my own.

I DO have a desire to learn, tho..........

18 Oct 2007, 4:52 PM
#25
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Multiple Images for One Listing Questions

Not directly in the stream of your work, but you have noted directories like /IMAGES/MEDIUM/ (in caps)... the stock directories are all lowercase. Could this have anything to do with the weirdness? Or was it just a device to show organization in your post?

18 Oct 2007, 5:25 PM
#26
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Multiple Images for One Listing Questions

The
// Check for additional matching images
block starting at line 39 does look for additional images in the base folder for the product, so you certainly would need to have files in that location in order for ZC to know to use the ones in /medium/. That's some very deep code in there, and I can't take time now to decipher it all. I guess the relevant question is, how does the code snippet referenced in posts above know to operate on the right base name... I'll have to look at that in depth later.

Another point - did you ever get the stock additional images function to work properly? Make sure you are doing that right before you introduce other variables like individual product/category subdirectories or making the additional images use the medium file instead of the small file.

18 Oct 2007, 9:22 PM
#27
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Re: Multiple Images for One Listing Questions

gjh42:

Not directly in the stream of your work, but you have noted directories like /IMAGES/MEDIUM/ (in caps)... the stock directories are all lowercase. Could this have anything to do with the weirdness? Or was it just a device to show organization in your post?


Glenn

Glenn---

Thans for the comment. I was actually just using ALL CAPS as I sometimes do in psots. I realize that this is poor practice, and just adds confusion to the issue. So the files ARE in the default folders, with the lower-case names.

gjh42:

The
// Check for additional matching images
block starting at line 39 does look for additional images in the base folder for the product, so you certainly would need to have files in that location in order for ZC to know to use the ones in /medium/.

I've experimented, and taking the base files out always keeps the corresponding additionals from displaying.

gjh42:

That's some very deep code in there, and I can't take time now to decipher it all. I guess the relevant question is, how does the code snippet referenced in posts above know to operate on the right base name... I'll have to look at that in depth later.

It seems that the base name is correct for the additional images....but the array component of the filename (_01, _02, etc) is missing or something. As I said, additionals will display at MED size, but the BASEFILE will be displayed in place of the correct additional image.

So that leads me to think that whatever part of the script is outputting the image name is completely missing the array part. What is the 'array component' string of the additional image file name called? (sorry, Im using my wn terminology here)

gjh42:

Another point - did you ever get the stock additional images function to work properly? Make sure you are doing that right before you introduce other variables like individual product/category subdirectories or

So it CAN be done? Im guesing I dont have to leave all my images in /images/, /large/, and /medium/ root dirs. I noticed the demo cart had subdirs. Any rules for this???

gjh42:

making the additional images use the medium file instead of the small file.

The stock additional images works perfectly, displaying the additionals as thumbnail-sized photos.

So that crosses a few possibilities off the list.........

THANKS AGAIN 4 the feedback!!

19 Oct 2007, 4:39 AM
#28
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Multiple Images for One Listing Questions

You may have already looked at this tutorial: How do I add multiple images to a product?, but study it again carefully. It has the answers to most of your questions, asked and unasked, about image files and product/category subdirectories.

The medium additional images are another issue. I had the feeling the base name was not getting the full additional image filename... will check into that more when I have time.

22 Oct 2007, 6:37 PM
#29
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Re: Multiple Images for One Listing Questions

gjh42:

You may have already looked at this tutorial: How do I add multiple images to a product?, but study it again carefully. It has the answers to most of your questions, asked and unasked, about image files and product/category subdirectories.

The medium additional images are another issue. I had the feeling the base name was not getting the full additional image filename... will check into that more when I have time.

I've been away........

Enthused to approach this freshly, tho...

OK, to review:

Multiple images display perfectly, with clickable tumbnails.

But when I want the MEDIUM-sized ones, I run into problems.

The changes made in the PHP file somehow do not work. I cannot figure out WHY, but they don't.

MEDIUM additional files are displayed, but they are just the base image, and not the base image_01, _02, etc. It's that one image in the product description repeated again and again beneath the image description.

But...the link to click for larger DOES take me to the correct larger images.

So for now Im setting it back to default thumbnail additionals.

Thats about all I can think of.

Anyone with any ideas, please consider contributing....

Anything would be helpful.........

23 Oct 2007, 1:48 AM
#30
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Re: Multiple Images for One Listing Questions

OK....So this is what I have established, or at least i THINK I have...lol

// check for a medium image else use small
$products_image_medium = $products_image_base . IMAGE_SUFFIX_MEDIUM . $products_image_extension;
if (file_exists(DIR_WS_IMAGES . 'medium/' . $products_image_medium)) {
$base_image = DIR_WS_IMAGES . 'medium/' . $products_image_medium;
}

This MUST be the offending code. Why? Because without the changes here and below, additonals display fine (as small thumbs). With these changes, I get all medium addtls, but the WRONG filenames. And this is the part that checks for the files, and then asssigns the correct filename to the images that will be the additoinals displayed. This is what is not working. Are these the correct strings? Correct syntax??

The BASE filename is used. But---not the array part (_01, _02, etc.) or the MED part. The addttnls are just small -sized images displayed at MED size.

$thumb_slashes = zen_image($base_image, addslashes($products_name), MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT);
$thumb_regular = zen_image($base_image, $products_name, MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT);

Since the additionals are displaying MED size, it seems this change to the PHP file is fine.

23 Oct 2007, 7:20 AM
#31
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Multiple Images for One Listing Questions

Before studying the rest of the file again, I observe that $products_image_base is the key to this. What is the value of that? If it is the additional image name (without _MED suffix), the correct medium additional image should be called. If it is the main product base (thumbnail) image name, it would give the results observed.

"MEDIUM additional files are displayed, but they are just the base image, and not the base image_01, _02, etc."

What is the full filename of the image being displayed? Is it the main thumbnail file or the main medium file?

23 Oct 2007, 1:43 PM
#32
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Multiple Images for One Listing Questions

Assuming you only want to use medium additional images, this will build the additional image list from the medium folder. You will not need additional image files in the thumbnail folder; the image names will need the _MED suffix.
The code is spread out more than DrByte's example. Find```php
$products_image_directory = str_replace($products_image, '', substr($products_image, strrpos($products_image, '/')));
if ($products_image_directory != '') {
$products_image_directory = DIR_WS_IMAGES . str_replace($products_image_directory, '', $products_image) . "/";
} else {
$products_image_directory = DIR_WS_IMAGES;
}

// Check for additional matching images
$file_extension = $products_image_extension;
$products_image_match_array = array();
if ($dir = @dir($products_image_directory)) {
while ($file = $dir->read()) {
if (!is_dir($products_image_directory . $file)) {
if (substr($file, strrpos($file, '.')) == $file_extension) {
// if(preg_match("/" . $products_image_match . "/i", $file) == '1') {
if(preg_match("/" . $products_image_base . "/i", $file) == '1') {
if ($file != $products_image) {
if ($products_image_base . str_replace($products_image_base, '', $file) == $file) {
// echo 'I AM A MATCH ' . $file . '<br>';
$images_array[] = $file;
} else {
// echo 'I AM NOT A MATCH ' . $file . '<br>';
}
and replace withphp
$products_image_directory = str_replace($products_image, '', substr($products_image, strrpos($products_image, '/')));
if ($products_image_directory != '') { //med add: product is in a subdir - insert medium/ into dir path
$products_image_directory = DIR_WS_IMAGES . str_replace($products_image_directory, '', $products_image) . "/";
$products_image_directory_medium = DIR_WS_IMAGES . 'medium/' . str_replace($products_image_directory, '', $products_image) . "/";
} else { //med add: product is in /images/ - insert medium/ into dir path
$products_image_directory = DIR_WS_IMAGES;
$products_image_directory_medium = DIR_WS_IMAGES . 'medium/';
}

// Check for additional matching images
$file_extension = $products_image_extension;
$products_image_match_array = array();
if ($dir = @dir($products_image_directory_medium)) { //med add: if med is valid dir
while ($file = $dir->read()) {
if (!is_dir($products_image_directory_medium . $file)) { //med add: if item being read is file, not subdir
if (substr($file, strrpos($file, '.')) == $file_extension) {
// if(preg_match("/" . $products_image_match . "/i", $file) == '1') {
if(preg_match("/" . $products_image_base . "/i", $file) == '1') {
if ($file != (str_replace($products_image_extension, '', $products_image) . IMAGE_SUFFIX_MEDIUM . $products_image_extension)) { //med add: check against main med img, not main thumb
if ($products_image_base . str_replace($products_image_base, '', $file) == $file) {
if (substr($file, strrpos($file, IMAGE_SUFFIX_MEDIUM)) == IMAGE_SUFFIX_MEDIUM . $file_extension) { //med add: if filename ends in _MED
// echo 'I AM A MATCH ' . $file . '<br>';
$images_array[] = $file;
} else {
// echo 'I AM NOT A MATCH ' . $file . '<br>';
} //med add: substr
}

Find```php
    $base_image = $products_image_directory . $file;
    $thumb_slashes = zen_image($base_image, addslashes($products_name), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
    $thumb_regular = zen_image($base_image, $products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
```and replace with```php
    $base_image = $products_image_directory_medium . $file; //med add: use med dir
    $thumb_slashes = zen_image($base_image, addslashes($products_name), MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT); //med add: medium w & h
    $thumb_regular = zen_image($base_image, $products_name, MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT); //med add: medium w & h
```Note: this is not yet tested. Please let me know how it works.
25 Oct 2007, 10:50 PM
#33
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Re: Multiple Images for One Listing Questions

Thanks for the code. I still haven't tried it.

Would your revision cause the thumbnails (displayed in categotry listings) to actually be the _MED file, just displayed smaller? I know that can slow down a page's load time.

PS where is the thumbnail folder you refer to?

As I understood it...the listing photo (thumbnail?) is in /images/

is there another thumbnail directory? Is the thumbnail something else, other than the image used for the category items listings?

25 Oct 2007, 11:02 PM
#34
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Re: Multiple Images for One Listing Questions

gjh42:

Before studying the rest of the file again, I observe that $products_image_base is the key to this. What is the value of that? If it is the additional image name (without _MED suffix), the correct medium additional image should be called. If it is the main product base (thumbnail) image name, it would give the results observed.

"MEDIUM additional files are displayed, but they are just the base image, and not the base image_01, _02, etc."

What is the full filename of the image being displayed? Is it the main thumbnail file or the main medium file?

It depends, actually.

If I upload the files to the /images/ root directory, as well as medium images to /images/medium, and larges to /images/large/, and point the product image dropdown to Main Directory.....

Additional files WILL display MEDIUM sized, BUT all of them will be the same EXACT file:

'image_MED.jpg'.

There will be exactly as many duplicate additional images displayed as there are files in the /images/ dir that have the same product name (and also containing additional characters after the name)

NOTE: As an additional test, Iadded some _MED files into the /images/ folder. Zencart counted these as well as the product_01, _02 files. In toher words, if I had 2 additional images in the /images/ dir, it would display 2 additional image_MED files. If I also add 2 more _MED files to the /images/ dir, it will display FOUR of the same duplicate _MED image

so...does that mean that ZC will treat ANY files in the /images/ folder (/images/subfolder/) as additionals, as long as the files contain ANY extra characters beyond the base name?

BUT....if I select a subfolder....(which is the way I plan to organize my products)
And do everything else the same, except upload the files to the subfolder in
images/subfolder

images/large/subfolder

and

images/medium/subfolder

what displays is exactly what would if I didn't have Dr. Zen's change in the script: I get the correct additionals, displayed in product listing size, NOT medium, even though the medium images are right there in the corresponding images/subfolder. If I ALSO put the _MED files in the /images/medium/ folder (Still having the product set to the sub-dir) i STILL get the same results: The correct additionals, obviously from the subfolder, only small sized.

Again, all large clickables are perfect, both with the above and below tests.

25 Oct 2007, 11:16 PM
#35
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Multiple Images for One Listing Questions

This code would not affect anything that would show on the listing page. The additional images are displayed only on the product info page.

25 Oct 2007, 11:26 PM
#36
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Multiple Images for One Listing Questions

"Additional files WILL display MEDIUM sized, BUT all of them will be the same EXACT file:

'image_MED.jpg'."

This is what I thought DrByte's code as posted would do.

The "subfolder" results I'm not sure about - wloud have to reanalyze the code to see what I think it should do.
At any rate, the code I posted will eliminate the need to put unused copies of additional images in the main /images/subfolder.

26 Oct 2007, 1:17 AM
#37
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Re: Multiple Images for One Listing Questions

gjh42:

"Additional files WILL display MEDIUM sized, BUT all of them will be the same EXACT file:

'image_MED.jpg'."

This is what I thought DrByte's code as posted would do.

The additional images are ALL just 'image_MED.jpg''
when they SHOULD be 'image_01_MED.jpg', 'image_02_MED.jpg', etc.

So I end up seeing the main product descrition photo repeated again and again in medium size, corresponding to the number of base images ZC finds. (If, and only if, I use /images as the DIR...again, subdirs do not work---using subdirs w/ Dr Zen's changes results in NO change at all...works exactly as it did before the alteration...displaying the CORRECT additional photos, but in SMALL size, even when _MED files are there and in the correct dir / subdir)

gjh42:

The "subfolder" results I'm not sure about - wloud have to reanalyze the code to see what I think it should do.

At any rate, the code I posted will eliminate the need to put unused copies of additional images in the main /images/subfolder.
Arent the images in the main/images(/subfoolder) supposed to be at lowest resolution., though?
If I use exclusively _MEd and _LRG files, wont ZC ahve to calculate the lo-res category listing photos from the _MEDs. Wont this slow the cart down?

Im confused as to how they'd be unused....

26 Oct 2007, 1:20 AM
#38
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Re: Multiple Images for One Listing Questions

gjh42:

This code would not affect anything that would show on the listing page. The additional images are displayed only on the product info page.

I keep getting the terminology mixed up...sorry about that...

What you wrote is what I MEANT to say....
PROD DESCRPTION page, and not the cat listings....

duh

26 Oct 2007, 1:26 AM
#39
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Re: Multiple Images for One Listing Questions

Donn:

If I use exclusively _MEd and _LRG files, wont ZC ahve to calculate the lo-res category listing photos from the _MEDs. Wont this slow the cart down?.

Or does the ZC just display the _MED files, smaller, but at the same effective resolution?

Both methods of dealing with a missing image file (no MEd or LRG suffix) would slow down the ZC software.

But Im still not sure what your code does....exactly....

Whaty do you mean about thumbnails? Are the image files (no suffix MED or LRG) the thumbnails you refer to?

26 Oct 2007, 7:50 AM
#40
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Multiple Images for One Listing Questions

The product base image (in /images/ or /images/your_subdir/) is the thumbnail: the smallest sized image.
You don't want additional images at thumbnail size, ever - that's what all the work is about, to get medium-sized additional images on the product info page.

The stock ZC code requires a thumbnail-sized image for every product image, main or additional. My mods change that to requiring a medium-sized image for the additional images, and a large image if desired.


Note: I have just noticed a bug in my code - the large images would need to be named filename_MED_LRG.jpg to work as written. It would be possible to strip the _MED from the base that generates the large filename, but it would be much simpler to eliminate a line of my code and not require the additional images in the /medium/ folder to have _MED in their names.
So... replace the first new code block in post 32 with```php
$products_image_directory = str_replace($products_image, '', substr($products_image, strrpos($products_image, '/')));
if ($products_image_directory != '') { //med add: product is in a subdir - insert medium/ into dir path
$products_image_directory = DIR_WS_IMAGES . str_replace($products_image_directory, '', $products_image) . "/";
$products_image_directory_medium = DIR_WS_IMAGES . 'medium/' . str_replace($products_image_directory, '', $products_image) . "/";
} else { //med add: product is in /images/ - insert medium/ into dir path
$products_image_directory = DIR_WS_IMAGES;
$products_image_directory_medium = DIR_WS_IMAGES . 'medium/';
}

// Check for additional matching images
$file_extension = $products_image_extension;
$products_image_match_array = array();
if ($dir = @dir($products_image_directory_medium)) { //med add: if med is valid dir
while ($file = $dir->read()) {
if (!is_dir($products_image_directory_medium . $file)) { //med add: if item being read is file, not subdir
if (substr($file, strrpos($file, '.')) == $file_extension) {
// if(preg_match("/" . $products_image_match . "/i", $file) == '1') {
if(preg_match("/" . $products_image_base . "/i", $file) == '1') {
if ($file != (str_replace($products_image_extension, '', $products_image) . IMAGE_SUFFIX_MEDIUM . $products_image_extension)) { //med add: check against main med img, not main thumb
if ($products_image_base . str_replace($products_image_base, '', $file) == $file) {//med add: filename must not end in _MED, to ease large file use
// echo 'I AM A MATCH ' . $file . '<br>';
$images_array[] = $file;
} else {
// echo 'I AM NOT A MATCH ' . $file . '<br>';
}

filename_01.jpg, and save in 
/images/medium/your_subdir/ .

----------------------------------------------------------------------
We have both spent a lot of time trying to describe what we think code may or may not do; it would save a lot of energy if you try the code and see what it does. If it doesn't work, I'll troubleshoot it. Save a copy of the original file (it should still be there at /includes/modules/additional_images.php) so if something goes wrong with /includes/modules/your_template/additional_images.php you can easily recover. This is standard procedure.