Announcement

Collapse
No announcement yet.

use a php generated image for thumbnail image in the checkout?

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

    #16
    No worries, I'm sure you are right but I have always liked my clients to be able to add a single image for a product which then generates any other smaller images to be used across the site.

    Just a shame it seems I can't do this if I want to use the images in the cart. Well at least I can't with with my knowledge of php and actinic...I'm sure someone else could and if they do I'd love them to share it on this post.

    Thanks again for the help
    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


      #17
      EncodedProductAnchor is available in the Cart. This is basically the product ID with all special characters replace by _nn so is always safe to use in filenames, id taglets, etc.
      Norman - www.drillpine.biz
      Edinburgh, U K / Bitez, Turkey

      Comment


        #18
        Hi Norman that is great, I'll test.
        However I have just added it in the template and Actinic produces a script error saying EncodedProductAnchor won't work in the cart product details.

        Lets give it a go anyway. I'll report back tomorrow
        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


          #19
          Ahah. It's not as easily accessible as I thought.

          You might have to use ProdRef and some JavaScript to escape the special characters and then generate the image filename. Also, this assumes that you always have an image for every product. E.g.

          'a' + escape('<actinic:variable name="ProdRef" />').replace(/%/g,'_')

          Will turn product ID's into anchors.
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #20
            Thanks for the help Norman but not being a javascript expert the next questions are:
            • How do i get the javascript to work?
            • Where do I put it?
            • And do I need to put anthing else around it other than


              <script language="JavaScript" type="text/javascript">
              <!--


              // -->
              </script>


            p.s It is very kind of you to help
            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


              #21
              The following in the cart product layout will display an image that's been created using filename

              t_<actinic:variable name="EncodedProductAnchor" />.jpg

              Code:
              <script language="JavaScript" type="text/javascript">
              <!--
                document.write('<img src="t_a' + escape('<actinic:variable name="ProdRef" />').replace(/%/g,'_') + '"/>');
              // -->
              </script>
              Norman - www.drillpine.biz
              Edinburgh, U K / Bitez, Turkey

              Comment


                #22
                Brilliant Norman,
                I'm going to give it a go then get back to the forum
                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


                  #23
                  Code from norman works a charm.

                  Here's what I have done (I'm sure it could be refined or done another way but someone else can post if I have done something unnessersary or plain wrong...it works for me though).

                  First I created a custom variable called it "CheckoutImageWidth" set it to show in site options. Made the type of variable "numeric" and set it to the size I wished the images to produce.

                  Then in the product layout to generate the image I have:

                  Code:
                  <actinic:block if="%3cactinic%3avariable%20name%3d%22IsProductImageDisplayed%22%20%2f%3e" >
                  	<actinic:block php="true" selectable="false">
                  $sOriginalImageName  = basename('<actinic:variable  encoding="perl" name="ProductImageFileName"  selectable="false" />');
                  $nScaledWidth = <actinic:variable name="CheckoutImageWidth" />;
                  $sProductID = basename('<actinic:variable encoding="perl" name="EncodedProductAnchor" selectable="false"/>');
                  $sThumbImageName = 'cart_' . basename($sProductID) . '.jpg';
                  if (file_exists($sThumbImageName)) {
                  echo "";
                  } 
                  else {
                  $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>";
                  }
                  }
                  }
                   	</actinic:block>  
                  
                  </actinic:block>
                  <span style="visibility:hidden"><img src="cart_<actinic:variable encoding="perl" name="EncodedProductAnchor" selectable="false"/>.jpg" alt="<actinic:variable name="ProductName" />" /></span>
                  (I added <span style="visibility:hidden"><img src="cart_<actinic:variable encoding="perl" name="EncodedProductAnchor" selectable="false"/>.jpg" alt="<actinic:variable name="ProductName" />" /></span> to force actinic to upload the image but hide it. I'm sure if you didn't want the images to be included on the page (allbeit hidden) you could create a custom popup page which included code to show all images and as long as you didn't provide links to the page it could be hidden from the site and used simply to force the upload).

                  Then in the cart product layout I have included:
                  Code:
                  <script language="JavaScript" type="text/javascript">
                  <!--
                    document.write('<img src="cart_a' + escape('<actinic:variable name="ProdRef" />').replace(/%/g,'_') + '.jpg"/>');
                  // -->
                  </script>
                  within <Actinic:REMOVE TAG="ImageLine"> and </Actinic:REMOVE> tags.


                  Thanks again everyone for all the help...especially Norman.
                  Regards
                  Lee
                  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

                  Working...
                  X