We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37909
    • 153 Posts
    Hello!

    First, I have a snippet:
    $content = preg_replace_callback( 
        '#\(\(image:(\d+)\)\)#i', 
        function($match) use ($listPict,$baseUrl) {
    		$p['image'] = $baseUrl.$listPict[$match[1]]['image'];
    		$p['titre'] = $listPict[$match[1]]['title'];
    		global $modx;
    		$chtml = $modx->parseChunk('photoContenu', $p);
    		return $chtml;
    	}, 
        $content 
    );
    return $content;

    Of course, I didn't put here the entire snippet, just what we need.

    Then, my chunk:
    <img src="[[!phpthumbof? &input=`[[+image]]` &options=`w=620&h=300&zc=1`]]" alt="[[+titre]]" />


    The picture appear but it's not cropping.

    If I change my snippet like this:
    $content = preg_replace_callback( 
        '#\(\(image:(\d+)\)\)#i', 
        function($match) use ($listPict,$baseUrl) {
    		$p['image'] = $baseUrl.$listPict[$match[1]]['image'];
    		$p['titre'] = $listPict[$match[1]]['title'];
    		$chtml = '<img src="[[!phpthumbof? &input=`'.$p['image'].'` &options=`w=900&h=500&zc=1`]]" alt="'.$p['titre'].'" />';
    		return $chtml;
    	}, 
        $content 
    );
    return $content;


    The picture appear and is cropping. But, It's a wrong way. I prefer to use a chunk. I guess you know how much it's better.

    So, somebody can help me?
    • Call the snippet phpthumbof cached in the chunk.
        • 37909
        • 153 Posts
        But it's already do. By the way, I tested cached and without cached and the result is always the same.
        • Then please try it with $modx->getChunk instead of $modx->parseChunk

          Or use:

                  $p['image'] = $baseUrl.$listPict[$match[1]]['image'];
                  $p['titre'] = $listPict[$match[1]]['title'];
                  $p['thumb'] = $modx->runSnippet('phpthumbof', array('input' => $p['image'], 'options' => 'w=900&h=500&zc=1'));
                  $chtml = $modx->parseChunk('photoContenu', $p);
          


          with this photoContenu chunk content:

          <img src="[[+thumb]]" alt="[[+titre]]" />
            • 37909
            • 153 Posts
            Doesn't work. So, I used again the method without chunk. Thank you anyway.