Announcement

Collapse
No announcement yet.

PHP thoughts? How to use ExtendedInfoImage and get image to resize

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

    PHP thoughts? How to use ExtendedInfoImage and get image to resize

    Hi all,
    Can anyone with knowledge of php help?

    Using v9 this is a problem when trying to use the php image resize method commonly used here: http://community.actinic.com/showthread.php?t=34654

    If you need it to apply to an Extend Info Image it produces errors in actinic particularly if images aren't directly in the site1 folder but in sub folders.

    Sometimes it outputs when you upload but this hasn't happened for me this time so I looked into the way ExtendedInfoImage and ProductImageFileName are handled.

    ExtendedInfoImage ouput example: ../folder/eximagehere.jpg
    ProductImageFilename (same image) example: folder\eximagehere.jpg

    So I guess to stop the error we need to create a version of the extendedinfoimage that removes the ../ and replaces any / (forward slash) with a \ (back slash).

    Does anyone know how to do this using php?
    I though something like this (but I don't know anything about php):
    <actinic:block php="true">echo basename(str_replace('/','\\', '<actinic:variable name="ExtendedInfoImage" encoding="perl" selectable="false" />'));</actinic:block>
    That strips the sub folders as well.
    If it could be done you could then apply it direct to the image resize php or create another custom layout and refer to it instead of the standard filename inside the php resize script.

    Sounds complicated but all i really need to know if how to remove ../ and replace / with \ using php.

    Really would appreciate the help.
    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

    #2
    Ok So removing basename allows for the forward slashes to change to backslashes without removing the directories:
    <actinic:block php="true">echo(str_replace('/','\\', '<actinic:variable name="ExtendedInfoImage" encoding="perl" selectable="false" />'));</actinic:block>
    But i also need the ../ to be removed before the script above replaces / with \.
    Can anyon help with createing something that will remove both ../ and replace / with \

    Hope somone can help,
    Cheers
    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
      I'd have thought you create a variable, apply the first change and assign that resulting value to the variable, then do your second change on the contents of the variable.

      Comment


        #4
        In Actinic V9 and V10, the ExtendedInfoImage file name is treated (buggily in my opinion) differently from the product image. It also behaves differently when Previewing compared with when generating live HTML. This makes it a nightmare to use in scripts. V10 introduced ExtendedInfoImageFileNameRaw which does work like the product image.

        The only way I've managed to get ExtendedInfoImage to work in V9 is to require the user to keep the Extended Info Image in the same place as the product image. You can then extract the path from the product image, concatenate it with the basename of the ExtendedInfoImage and get a clean filepath / name. A lot of coding. May be cheaper to upgrade to V10.
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #5
          Here's the Kludge I use in my Multi Product Images for V8/9.
          Code:
          // Actinic bug.  Use location of product image if extended info image found there.
          $mainimagefilename = '<actinic:variable name="ExtendedInfoImage" encoding="perl" selectable="false" />';
          $prodimagefilename = '<actinic:variable name="ProductImageFileName" encoding="perl" selectable="false" />';
          if ( $prodimagefilename )
          	{
          	$possibleimagefilename = dirname($prodimagefilename) . '/' . basename($mainimagefilename);
          	if ( file_exists($possibleimagefilename) )
          		{
          		$mainimagefilename = $possibleimagefilename;
          		}
          	}
          $mainimagefilename = str_replace ( '\\', '/', $mainimagefilename);		// replace troublesome backslashes
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            Thank you both.
            What a nightmare of a day, project overdue + this problem + i still had to go off for wedding prepartions (2 weeks time). STRESSED!

            Lee you are thinking the same way I have done on it so far but not being PHP whiz I can't see a way of doing it without solving my first problem.

            Norman - I'll give your code a shot, Thanks again for the help.

            Moving to v10 - yes please, but not an option.
            Not using extended info images now that would be good (I wouldn't have had to use unless they had already been in place). Problem is that clients site is messy, old basic and been a nightmare up to this stage to convert (last developer must have had basic knowledge of actinic with no long term view on work carried out). + I was an idiot not to have seen problems earlier.

            Thanks again
            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


              #7
              Hi Norman,
              Just a heads up and a thanks for your code, it works a dream on those in the same folder, which there are many, unfortuneately as you'd expect on a site so badly organised many are in different folders, I'm going to look into if they can feasbily sort out the structure to be logical at least and adopyt a method in whih they share the same folder.

              Cheers
              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


                #8
                OMG Have I cracked it?

                I have a feeling I may have written my first bit of php and I may have cracked this issue. Put it this way it works for me.

                I would love a PHP guru to try out and see if it works or if they can see any holes but this seems to solve it..shame it is about as useful as a chocolate teapot for most now they have v10.

                This is what I came up with:
                <actinic:block php="true">
                $find = array('../', '/');
                $replace = array('', '\\');
                $image = '<actinic:variable name="ExtendedInfoImage" encoding="perl" selectable="false" />';
                $imagereplace = str_replace($find, $replace, $image);
                echo $imagereplace;
                </actinic:block>
                Applied directly to the image resize code looks something like this:
                <actinic:block php="true" >
                // START Create a thumbnail image t_ProductImageFileName
                $find = array('../', '/');
                $replace = array('', '\\');
                $image = '<actinic:variable name="ExtendedInfoImage" encoding="perl" selectable="false" />';
                $ImageReplace = str_replace($find, $replace, $image);
                $sOriginalImageName = str_replace('\\','/', $ImageReplace);
                $nScaledWidth = 67;
                $sThumbImageName = 'gallery_sml/sml_' . 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 "";
                }
                }
                </actinic:block>
                And it works!!!! (as far as I can tell).
                Please test and let me know if it works for you.
                Cheers
                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


                  #9
                  Have you tried uploading?

                  I've never found code that works on Preview and Live pages.

                  Test with Extended Info images in both the Site folder and a sub-folder of it.
                  Norman - www.drillpine.biz
                  Edinburgh, U K / Bitez, Turkey

                  Comment


                    #10
                    Not yet fingers crossed
                    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


                      #11
                      Bol**x it doesn't work once uploaded.
                      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


                        #12
                        Yep! Afraid that's what I found.

                        Constrain your client to keeping the Extended Info and Product images in the same place and use code like I posted and you'll at least be working.
                        Norman - www.drillpine.biz
                        Edinburgh, U K / Bitez, Turkey

                        Comment

                        Working...
                        X