We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24183
    • 19 Posts
    What is the problem here?

    On some of my pages I get png images shown in some pages and not in some others. I think it’s strange. I tried copying source from one working page to one non-working page, and it did not work, though the "view Source" was identical...

    A working page is here:
    http://www.qson.se/modx/tjanster.html
    And a Non-working is:
    http://www.qson.se/modx/tjanster/webb.html

    At the bottom of the non-working page I pasted the code from the working page. It does’nt work here!

    Please help!
      • 24183
      • 19 Posts
      Finally I solved it Myself!

      The problem was that images was not shown when using a "subdirectory" e.g. domain.com/alias1/product1.html because usual img tags use the BASE HREF tag and AlphaImageLoader don’t. The urls were relative to this subdirectory and there is no image file in domain.com/alias1/assets/images/blablabla.png.

      I modified the source to read out the base href url and prepend it to the relative path of the image.

      Here’s my code:
      First a function to get the base url from the document. (This can be placed anywhere in the code, but I places it just below the switch-statement on top.
      /* Functions for including BASE HREF support */
      /* By Qson */
      function get_base_href($body=null) {
      	if ($body==null) {
      		global $modx;
      		$body=$modx->documentOutput;
      	}
      	preg_match("/<base[^>+]href\s*=\s*([\"'])?(?(1)(.*?)\\1)[^>*]\/?>/is", $body, $matches);
      	return $matches[2];
      }
      
      function add_base_href($url) {
      
      	global $base_href;
      
      	if (!isset($base_href)||empty($base_href)){
      		$base_href=get_base_href();
      	}
      
      	/* If the url is neither absolute (begins with http:// or ftp://) nor relative to root (begins with a slash) */
      	if( preg_match('/^((http|ftp)\:\/\/|[\/\\\]).*/is',$images[3][$num_images])==0) {
      		// The url is relative to this directory, let's prepend the base href
      		return $base_href . $url;
      	} else {
      		// The url is absolute or root relative. Just return it as is.
      		return $url;
      	}
      
      }
      
      /* End of Qson Functions */

      At the bottom of the source:
      Replace the following:
              // end quote is already supplied by originial src attribute 
              $replace_src_with=$quote.$img_path.'spacer.png'.$quote.' style="width: '.$width. 
                  '; height: '.$height.'; filter: progid:DXImageTransform.'. 
                  'Microsoft.AlphaImageLoader(src=\''.$images[3][$num_images].'\', sizingMethod='. 
                  $sizeMeth.');"';
      with
              // end quote is already supplied by originial src attribute 
              $replace_src_with=$quote.$img_path.'spacer.png'.$quote.' style="width: '.$width. 
                  '; height: '.$height.'; filter: progid:DXImageTransform.'. 
                  'Microsoft.AlphaImageLoader(src=\''.add_base_href($images[3][$num_images]).'\', sizingMethod='. 
                  $sizeMeth.');"';
        • 7923
        • 4,213 Posts
        If I get it correctly what you are talking about, I think you could go without your functions and just add $modx->config[’base_url’] to the src path..


          "He can have a lollipop any time he wants to. That's what it means to be a programmer."
          • 24183
          • 19 Posts
          Yeah, thought about that too... But too late. I already wrote this code and I have no time to rewrite it. (It woldnt take much time though wink) Maybe I’ll do it later. It works for the moment and that’s ok for me.

          (/Sorry for losing some apostrophes’’’’)...
            • 14779
            • 256 Posts
            I have been looking for a LONG time for a fix to the PNG transparency issue with IE. I have reverted all my graphics back to GIF’s and JPEG’s, as I was not able to get the plugin working.

            I have just found an incredible, simple solution.
            Just paste this into your header:

            <!--[if gte IE 5.5000]>
            <script language="JavaScript">
            function correctPNG()
            {
               for(var i=0; i<document.images.length; i++)
               {
                  var img = document.images[i]
                  var imgName = img.src.toUpperCase()
            
                  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
                  {
                     var imgID = (img.id) ? "id='" + img.id + "' " : ""
                     var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                     var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                     var imgStyle = "display:inline-block;" + img.style.cssText
            
                     if (img.align == "left") imgStyle = "float:left;" + imgStyle
                     if (img.align == "right") imgStyle = "float:right;" + imgStyle
                     if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            
                     var strNewHTML = "<span " + imgID + imgClass + imgTitle
                         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;"
                         + imgStyle + ";"      + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
            
                     img.outerHTML = strNewHTML
                     i = i-1
                  }
               }
            }
            window.attachEvent("onload", correctPNG);
            </script>
            <![endif]-->


            The URL for the web page is here:

            http://www.troozers.com/joomla!/howto/png_fix.html
              PM me to find out how you can get a FREE ipad 2!
              • 6726
              • 7,075 Posts
              I have to try that !
              Thanks for the pointer and fix smiley

              Only problem with this js method is if javascript is disabled...
                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l&#39;outil id
                • 14779
                • 256 Posts
                Only problem with this js method is if javascript is disabled...

                Yeah, well you can’t have everything! wink

                what I liked about this, was that it is very simple, and it just works.

                If you want to see the site I’m using it on, look at:
                http://beesnblossoms.com
                  PM me to find out how you can get a FREE ipad 2!
                  • 32443
                  • 37 Posts
                  just in case it hasn’t been answered your css will no longer validate if you use the css method.

                  regardless of what you do

                  you html will be fine

                  if you are as anal as i am though, you gotta use javascript to implemented it so that everything will still validate. If people have javascript disabled and are using ie just put a sign that says they’re missing out wink
                    call it ModSeX o yeah smiley

                    check us out and we need help Upscale Webservices http://www.upscalews.com/
                    • 33372
                    • 1,611 Posts
                    Quote from: williscool at Dec 02, 2006, 06:21 AM

                    just in case it hasn’t been answered your css will no longer validate if you use the css method.

                    regardless of what you do

                    you html will be fine

                    if you are as anal as i am though, you gotta use javascript to implemented it so that everything will still validate. If people have javascript disabled and are using ie just put a sign that says they’re missing out wink

                    Well... yes and no...

                    You can PHP-script your CSS file to send the funky IE6 transparency code only when the browser viewing the page is IE6, so for all other browsers it will validate (and IE6 won’t complain, of course).

                    Luckily Microsoft has started pushing IE7 out via Automatic Updates, so this will be less and less of a problem now.
                      "Things are not what they appear to be; nor are they otherwise." - Buddha

                      "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                      Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                      • 17717
                      • 433 Posts
                      Does anyone know if the plugin works with version .95

                      Thanks
                      Lee
                        http://www.blend.uk.com | Web Design by Blend