We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25969
    • 118 Posts
    It’s just string manipulation but I can’t figure it out. I have a thumb script expecting an image request in the form of
    /thumb/assets/images/example/image.100x100.png

    where the image "/assets/images/example/image.png" will be cropped and resized to 100x100 pixels and cached. So I’ve set up an image TV and in the template using a script basically like the one below (which excepts &img)

    return '/thumb' . substr($img, 0, -strlen(strrchr($img, '.'))) . '.100x100.' . end(explode('.', $img));

    In testing locally this works fine however as a snippet it ends up as
    /thumb.100x100./assets/images/example/image.png


    Any ideas?
      • 25969
      • 118 Posts
      OK, so I’ll reframe the question since it’s prob confusing.

      I’m using an image TV to save an image path against a document. However I need a snippet to reformat the image path from (for example)

      /assets/images/article/image.jpg

      to
      /thumb/assets/images/article/image.120x120.jpg

      I would have the thought the above "snippet" would have done the job but my code returns
      /thumb.120x120./assets/images/article/image.jpg


      Halp?
        • 4310
        • 2,310 Posts
        <?php
        $source = 'This is the current path to the image :
        /assets/images/article/image.jpg';
        $source = str_replace('/assets/images/article/','/thumb/assets/images/article/',$source);
        $source = str_replace('.jpg','.120x120.jpg',$source);
        return $source;
        ?>

        I’ve split the changes into two sections, everything before the image name, then the file extension.
        There will be a more elegant way to do this, but I’m just a dirty hacker wink