We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Hi Adam,

    I'd start with just <img src="[[+image]]"> first and see what that's doing. When you view the source of the generated page, what do you see?
    Is it <img src="//assets/images/article-images/2011/11/image-name.jpg"> (leading double slash)? In that case it's the double slash that's confusing it. pThumb looks at the first few characters to see if it's an absolute URL. If it's 'http:', 'https:' or just '//' (a protocol-relative URL) then it assumes it is. If this is indeed what's happening, fix your media source so that it produces a correct relative url: '/assets/images/article-images/2011/11/image-name.jpg' and then things should work fine.

    If it's something else, post it and I'll see if I can figure it out : )

    I'm going to improve that part of the code a bit so it handles these cases better. [ed. note: jgrant last edited this post 10 years, 8 months ago.]
      Extras :: pThumbResizerimageSlimsetPlaceholders
    • Ah, it was the double slash coming from the media source, I'd set it to "/assets/images/" but changing it to just "assets/images" fixed the problem.

      I've gotta say now its all working the thumbnail generator you've made here is very snappy! Great work!
        MODX Ambassador for Thailand. Managing Director at Monogon, a web design and development studio based in Bangkok, Thailand. - Follow me on Twitter.
        • 3749
        • 24,544 Posts
        Quote from: jgrant at Aug 28, 2013, 01:32 PM
        Hi Adam,

        I'd start with just <img src="[[+image]]"> first and see what that's doing. When you view the source of the generated page, what do you see?
        Is it <img src="//assets/images/article-images/2011/11/image-name.jpg"> (leading double slash)? In that case it's the double slash that's confusing it. pThumb looks at the first few characters to see if it's an absolute URL. If it's 'http:', 'https:' or just '//' (a protocol-relative URL) then it assumes it is. If this is indeed what's happening, fix your media source so that it produces a correct relative url: '/assets/images/article-images/2011/11/image-name.jpg' and then things should work fine.



        I'm going to improve that part of the code a bit so it handles these cases better.

        I've found it handy apply various of these transforms to path and URL parts to guarantee that they look like I want them to, especially if users are configuring them with properties or system settings:

        /* delete trailing slash */
        $dir = rtrim('/\\', $dir);
        
        /* delete leading slash */
        $dir = ltrim('/\\', $dir);
        
        /* delete both */
        $dir = trim('/\\', $dir);
        
        /* Add back when appropriate */
        $path = $dir . '/' . $path;
        
        /* Remove double slashes */
        $path = str_replace('//', '/', $path);
        $path = str_replace('\\\\', '\\');


        This is also useful if you want to compare paths or URLs for equality and you're not sure what platform you're on:

        function normalize($path) {
                return strtolower(str_replace("\\", '/', $path));
        }
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
        • Quote from: AdamWintle at Aug 28, 2013, 05:56 PM
          Ah, it was the double slash coming from the media source, I'd set it to "/assets/images/" but changing it to just "assets/images" fixed the problem.

          Yeah, media source configuration can get a bit tricky, what with basePath, basePathRelative, baseUrl and baseUrlRelative. Anyway, I'm glad you got it sorted. I've improved this for the next release, so in the future it'll handle multiple leading slashes without complaint—in most cases—yet still do the right thing for a valid URL like //imagecdn.mysite.com/image.jpg.

          I've gotta say now its all working the thumbnail generator you've made here is very snappy! Great work!

          Thanks!
          If you're just scaling and cropping images, be sure to enable Resizer (not enabled by default) and give that a try. It should make things snappier yet.

          Bob, thanks for the tips. This is another of those seeming simple issues which is actually quite thorny when you consider all the "correct but obscure" and "technically incorrect, but still perfectly clear" inputs. I'm sure I'll be tweaking this again in the future smiley
            Extras :: pThumbResizerimageSlimsetPlaceholders
            • 3749
            • 24,544 Posts
            Quote from: jgrant at Aug 29, 2013, 01:21 AM

            Bob, thanks for the tips. This is another of those seeming simple issues which is actually quite thorny when you consider all the "correct but obscure" and "technically incorrect, but still perfectly clear" inputs. I'm sure I'll be tweaking this again in the future smiley

            No kidding. I've had plenty of trouble with it, and I'm the only developer on my web sites.

            My general policy now is to follow the MODX standard of having all paths end with a slash when possible. When that's not possible, I strip all final slashes with trim() and put them back at the point where I need them. There are some platforms where mkdir() doesn't like the trailing slash.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
            • So what's the difference between pThumb and Resizer?
                MODX Ambassador for Thailand. Managing Director at Monogon, a web design and development studio based in Bangkok, Thailand. - Follow me on Twitter.
              • One more thing, so with pThumb is it possible to not even install phpThumbsOf on a website; or should both be installed anyway?

                If just pThumb is installed what would be the snippet call?
                  MODX Ambassador for Thailand. Managing Director at Monogon, a web design and development studio based in Bangkok, Thailand. - Follow me on Twitter.
                • You can think of the image manipulation "stack" in MODX as having a few layers:

                  3] User level. A snippet you can use in your templates. Ex: phpThumbOf, pThumb, phpThumbsUp, etc.
                  2] System level. A PHP class or classes. Ex: phpThumb/modPhpThumb (part of the MODX core), Resizer.
                  1] Lower level. A PHP extension or command-line program that does the actual work of manipulating an image. Ex: GD, ImageMagick, Gmagick.

                  pThumb handles looking for the file from the input you give it, seeing if it's already cached or not and if it isn't, generating a cache filename and passing that along with the input filename and options down to level 2. On level 2 it can either use phpThumb from the MODX core or Resizer, which pThumb installs.

                  phpThumb is old (it'll run on PHP 4.0-4.1, circa 2001!), supports a ton of options (need to add a border to your image, make it 20% transparent and rotate it 10° without that "new-fangled" CSS nonsense? : ), and while it mostly works ok, is something of a lumbering beast (have a look. And here). Development tapered off around 2007–2008 except for some bug fixes in 2011.

                  Resizer is my attempt at something lighter, faster, and somewhat more modern, focusing on the stuff people need most commonly these days, namely scaling and cropping images. I might add watermarking sometime. If you need to desaturate an image on the fly and apply a Gaussian blur, you can either use CSS3 filters or phpThumb.
                  Right now it consists of this library—which it uses only a fairly small part of—plus about 250 lines of code.

                  Hopefully that explains things?
                    Extras :: pThumbResizerimageSlimsetPlaceholders
                  • Quote from: AdamWintle at Aug 29, 2013, 05:17 AM
                    One more thing, so with pThumb is it possible to not even install phpThumbsOf on a website; or should both be installed anyway?

                    Yep, there's no need for phpThumbOf 1.4.0. I'd recommend uninstalling it—or not installing it to begin with—before installing pThumb. It's less confusing that way. If you install one on top of the other I think things'll still work (since they use the same snippet name and namespace, one overwrites the other), but if you later uninstall one, you'll inadvertently also uninstall most of the other.
                    Not a big deal—just reinstall the one you want—but best to avoid that can of worms in the first place.

                    If just pThumb is installed what would be the snippet call?

                    Also phpthumbof. It's a little weird, but it makes for an easy retrofit for existing sites. If you don't need the S3 support you can uninstall phpThumbOf, install pThumb and be all upgraded without changing anything in your templates.

                    It works a little like Google Chrome Frame in IE, or some parasites; it leaves the skin while replacing the guts.
                      Extras :: pThumbResizerimageSlimsetPlaceholders
                      • 36562
                      • 94 Posts
                      I can get phpthumbof to work, but not pthumb. I am wondering if you know of any differences that may cause this? I am guessing this is server related. I do have gd bt not imagequick installed.

                      Edit just ran debug mode and it seems as if it cant find the file. Any idea if i should dig into the server conf or if i should change any modx setting?

                      My call:
                      <img src="[[*image:phpthumbof=`w=100&h=400&zc=1&debug=1`]]">

                      Created path:
                      <img src="assets/havsvidden2.jpg">

                      Beginning of Error:

                      [2013-11-04 18:12:38] (ERROR @ /Users/williamastrom/Development/test.dev/public/core/model/phpthumb/phpthumb.class.php : 3210) PHP warning: file_get_contents(/Library/WebServer/Documentsassets/havsvidden2.jpg): failed to open stream: No such file or directory
                      [2013-11-04 18:12:38] (ERROR @ /index.php) [pThumb] Resource: 1 || Image: assets/havsvidden2.jpg
                      Could not generate thumbnail
                      phpThumb debug output:
                      [0] => phpThumb() v1.7.9-200712090829 in file "phpthumb.class.php" on line 216
                      [1] => setSourceFilename(assets/havsvidden2.jpg) set $this->sourceFilename to "assets/havsvidden2.jpg" in file "phpthumb.class.php" on line 243
                      [2] => file_exists() = 0 in file "phpthumb.class.php" on line 1101


                      Edit2:
                      Interestingly enough.. I chose to use resizer ( which one should obviously, but i just got stuck on using it with the old crap ) and then it works.. So it works and i wont look into it any further.. Just leaving it here in case anyone else has the same issue in the future.
                      /w [ed. note: DesignByWilliam last edited this post 10 years, 5 months ago.]
                        --------------------------------------
                        www.williamastrom.se