Announcement

Collapse
No announcement yet.

Automatically create Section images from 1st product with a jpg image.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Automatically create Section images from 1st product with a jpg image.

    Automatically create Section images from 1st product within that section that has a jpg image.

    If a section image is defined it will be used.
    If no section image is defined then the products within that section are searched for one with an image.
    If no product image exists then the default section image is used.



    INSTALLATION

    In your Site folder, create a sub-folder called "Thumbnails".


    Go to Design / Library / Variables / Section.
    Right-click Section and choose New Variable.
    Set the new variable as follows:
    Code:
    Name:			SectionImageScaledWidth
    Description:		Automatically resized section image from product image.
    Prompt:			Section Image Scaled Width
    Group:			Section
    Place Of Setting	Site	
    Allow <Use Parent>...	Checked
    Tab Name / Panel Name:	Layout
    Type:			Number
    Allow Empty Value:	Unchecked
    Whole Numbers Only:	Checked
    Searchable:		Unchecked
    Modifiable In Dup:	Unchecked
    Upload:			Unchecked
    Initial Value		Use Parent
    Top Level Value		75

    Go to Design / Library / Layouts / Section Links.
    Right-click "CSS Section Link layout" and select Copy.
    Rename that copy layout to be "CSS Section with Product Image Thumbnail".
    Open layout "CSS Section with Product Image Thumbnail".
    Replace the entire contents of that layout with the following:

    Code:
    <div class="product_list">
     <div class="image_product">
      <a href="<actinic:block if="%3cactinic%3avariable%20name%3d%22IsLoginPageSuppressed%22%20%2f%3e%20AND%0d%3cactinic%3avariable%20name%3d%22UnregCustomersAreNotAllowed%22%20%2f%3e" ><actinic:variable name="SectionPageName" /></actinic:block><actinic:block if="%28%3cactinic%3avariable%20name%3d%22IsLoginPageSuppressed%22%20%2f%3e%20%3d%3d%20false%29%20OR%0d%28%3cactinic%3avariable%20name%3d%22UnregCustomersAreNotAllowed%22%20%2f%3e%20%3d%3d%20false%29" ><actinic:variable name="SectionURL" /></actinic:block>" target="_self">
       <actinic:block php="true" >
    	// V1.03
    	$noimageyet = true;
    	if ( ( basename('<actinic:variable encoding="perl" name="SectionImageFileName" selectable="false" />') == basename('<actinic:variable name="DefaultSectionImage" encoding="perl" selectable="false" />') )
    		 || ( basename('<actinic:variable encoding="perl" name="SectionImageFileName" selectable="false" />') == basename('<actinic:variable name="MainSection::SectionImageFileName" encoding="perl" selectable="false" />') ) )
    		{
    		<actinic:block type="ProductList" >
    		$sOriginalImageName = '<actinic:variable encoding="perl" name="ProductImageFileName" selectable="false" />';
    		if ( $noimageyet && ($sOriginalImageName != "") && strpos(strtolower($sOriginalImageName), '.jpg') )
    			{
    			$sOriginalImageName = str_replace('\\','/', $sOriginalImageName);
    			$nScaledWidth = <actinic:variable name="SectionImageScaledWidth" encoding="perl" selectable="false" />;
    			$sThumbImageName = 'Thumbnails/s_' . basename($sOriginalImageName);
    			$image = @imagecreatefromjpeg($sOriginalImageName); /* Attempt to open */
    			if (!$image) 
    				{ /* See if it failed */
    				echo "<br><font color=red>Thumbnail creation error opening: $sOriginalImageName </font>";
    				}
    			else
    				{
    				// Get new dimensions
    				$width = imagesx($image);
    				$height = imagesy($image);
    				$t_width = $nScaledWidth;
    				$t_height = round($height * ($t_width / $width));
    				// Resample
    				$thumbimage = imagecreatetruecolor($t_width, $t_height);
    				imagecopyresampled($thumbimage, $image, 0, 0, 0, 0, $t_width, $t_height, $width, $height);
    				if ( ! imagejpeg($thumbimage, $sThumbImageName) ) 
    					{
    					echo "<font color=red>Thumbnail image creation failed: $sThumbImageName </font><br>";
    					}
    				else
    					{
    					echo "<img src=\"$sThumbImageName\" width=\"$t_width\" height=\"$t_height\" border=\"0\"";
    					echo " alt=\"<actinic:variable name="SectionName" encoding="strip"/>\" />";
    					}	
    				}
    			$noimageyet = false;
    			}
    		</actinic:block>
    		}
    	if ( $noimageyet )
    		{
    		echo "<img src=\"<actinic:variable encoding="perl" name="SectionImageFileName" selectable="false" />\"";
    		echo " width=\"<actinic:variable name="SectionImageWidth" />\"";
    		echo " height=\"<actinic:variable name="SectionImageHeight" />\" border=\"0\"";
    		echo " alt=\"<actinic:variable name="SectionName" encoding="strip"/>\" />";
    		}
       </actinic:block>
      </a>
     </div>
     <div>
     <h3 class="product"><a href="<actinic:block if="%3cactinic%3avariable%20name%3d%22IsLoginPageSuppressed%22%20%2f%3e%20AND%0d%3cactinic%3avariable%20name%3d%22UnregCustomersAreNotAllowed%22%20%2f%3e" ><actinic:variable name="SectionPageName" /></actinic:block><actinic:block if="%28%3cactinic%3avariable%20name%3d%22IsLoginPageSuppressed%22%20%2f%3e%20%3d%3d%20false%29%20OR%0d%28%3cactinic%3avariable%20name%3d%22UnregCustomersAreNotAllowed%22%20%2f%3e%20%3d%3d%20false%29" ><actinic:variable name="SectionURL" /></actinic:block>" target="_self"><actinic:variable name='SectionName'/></a></h3>
     </div>
     <p><actinic:variable name='SectionDescription'/></p>
    </div>
    That's installation done.


    OPERATION

    To select this layout, go to Settings / Site Options / Layout / Section
    and set Section Link Layout to "CSS Section with Product Image Thumbnail".

    To alter the image width, go to Settings / Site Options / Layout / Section
    and set Section Image Scaled Width as required.
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    #2
    Loving your work Norman!
    Off to a meeting this morning but will try out on my return.
    Thanks for all the help (holding my hand through the php implementation).
    Will post results from my site when finished (will make you a donation as soon as I can)
    regards
    Bangers
    Boxhedge New Media Design
    Design and development solutions for SME's.
    Tel: 0118 966 2786
    Examples of work can be found at http://www.boxhedge.com

    Comment


      #3
      Hi,
      This is indeed a thing of beauty but it does raise one problem for me and I was wondering if anyone clever out there can think of a work around.
      Tracey at budgetbumps first saw the potential problem see: http://community.actinic.com/showthread.php?t=34648

      The problem being that everything works as I'd wish unless a parent section has a section image assigned to it in which case that image overrides the display of the product image as section image...bit confusing, I'll try to explain with the below

      full catalogue
      section1 > has section image
      sub section > no image assigned
      product > product image

      What I would like to happen is for the sub section image to be formed from the product image.

      Instead because section1 has a section image it use that instead. If section1 doesn't have an image then the sub section image does get created from the product image, however this is not possible unless you want to end up with a list of top level sections with no image assigned to them when you view the page listing them.

      Any ideas?

      Regards
      Bangers
      Boxhedge New Media Design
      Design and development solutions for SME's.
      Tel: 0118 966 2786
      Examples of work can be found at http://www.boxhedge.com

      Comment


        #4
        Just FTR, I didn't find a way round it. I ended up copying the product image, as the layout is scaling it anyway, to the section image prompt each time.
        I'm definitely interested if anyone has any ideas!
        Tracey

        Comment


          #5
          Try this and report if it helps.

          In layout CSS Section with Product Image Thumbnail look for the line:
          Code:
          	if ( basename('<actinic:variable encoding="perl" name="SectionImageFileName" selectable="false" />') != basename('<actinic:variable name="DefaultSectionImage" encoding="perl" selectable="false" />') )
          Replace it with:
          Code:
          	if ( basename('<actinic:variable encoding="perl" name="SectionImageFileName" selectable="false" />') != basename('<actinic:variable name="MainSection::SectionImageFileName" encoding="perl" selectable="false" />') )
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            FANTASTIC!!

            works perfectly, Norman, thank you, thank you
            Tracey

            Comment


              #7
              In the words of a fizzy pop company "I'm lovin' it"

              Thanks,

              Bangers
              Boxhedge New Media Design
              Design and development solutions for SME's.
              Tel: 0118 966 2786
              Examples of work can be found at http://www.boxhedge.com

              Comment


                #8
                Great. I've amended my post #1 above to add in that post #5 update.

                I've also added a V1.01 comment to the amended post so people can see if they've the latest version.
                Norman - www.drillpine.biz
                Edinburgh, U K / Bitez, Turkey

                Comment


                  #9
                  Just gone live with http://shop.swimmingwithoutstress.co.uk...finally!

                  working version of this method. Just visit one of the sub sections (not top level) to see the images being created.
                  regards
                  bangers

                  p.s Thanks again Norm (p.p.s nice use of v8 image next to radio button being used)
                  Boxhedge New Media Design
                  Design and development solutions for SME's.
                  Tel: 0118 966 2786
                  Examples of work can be found at http://www.boxhedge.com

                  Comment


                    #10
                    Originally posted by NormanRouxel View Post
                    Try this and report if it helps.

                    In layout CSS Section with Product Image Thumbnail look for the line:
                    Code:
                    	if ( basename('<actinic:variable encoding="perl" name="SectionImageFileName" selectable="false" />') != basename('<actinic:variable name="DefaultSectionImage" encoding="perl" selectable="false" />') )
                    Replace it with:
                    Code:
                    	if ( basename('<actinic:variable encoding="perl" name="SectionImageFileName" selectable="false" />') != basename('<actinic:variable name="MainSection::SectionImageFileName" encoding="perl" selectable="false" />') )
                    this mod hasn't worked for me using 903, so i just bodged it by replacing the code with "nn" where nn is the width ie 75.

                    you can see this mod along with norm's product autosizer at testing.lessbounce.com/acatalog/

                    the beauty of this is my client doesn't have to manipulate any product/section images, she just feeds a square image into site folder and the rest is done.

                    Comment


                      #11
                      Just realised i may be abit arrogant here, i may not have done the install correctly

                      refering to norm's first post
                      Code:
                      Tab name: Layout
                      i didn't find this

                      Comment


                        #12
                        however i have coding errors...
                        Attached Files

                        Comment


                          #13
                          Jo,

                          Don't know where those errors are coming from.

                          However, I've amended my post #1 to have updated code (V1.03) for "CSS Section with Product Image Thumbnail". Try using that.

                          And it also notes that "Tab Name" is known as "Panel Name" in V9 speak.
                          Norman - www.drillpine.biz
                          Edinburgh, U K / Bitez, Turkey

                          Comment


                            #14
                            even with the new layout i still get coding errors and parse errors.

                            I got parse errors with gabe's section aware nav, so i know its not the code as supplied by Norm.

                            So i give up - I've tried 2 community remedys for parse errors

                            ie http://community.actinic.com/showthr...ht=parse+error

                            and

                            the push button error where it could be due to ' in section names

                            neither remedy fixes it

                            Comment


                              #15
                              even with the new layout I still get coding errors and parse errors
                              Hmmm... Looks like it's your system. I've just installed this on a 903IMMA and it works fine.

                              It might be worth installing Actinic onto a spare system and see if things are OK there (start with a demo site and if that's OK try installing a Snapshot).
                              Norman - www.drillpine.biz
                              Edinburgh, U K / Bitez, Turkey

                              Comment

                              Working...
                              X