S
S
sl4m_mc2018-03-24 10:25:58
MODX
sl4m_mc, 2018-03-24 10:25:58

How to process images via phpthumbof?

Hello! The challenge is to watermark the images in the content code.
Is there a plugin or snippet for this task?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sl4m_mc, 2018-03-24
@sl4m_mc

Made. Making a snippet:

<?php
  // Вызов 
    preg_match_all(
        '/<img[^>]+src="?\'?([^"\']+)"?\'?[^>]*>/i',
        $content,
        $matches
    );
    if (!empty($matches[0]))
    {
        foreach ($matches[0] as $key => $tag) {
            $link = preg_match_all('/<img[^>]+src="?\'?([^"\']+)"?\'?[^>]*>/i', $tag, $matches2, PREG_SET_ORDER);
            $new_link = $modx->runSnippet('phpthumbon', array('input' => $matches2[0][1], 'options' => 'w=200&h=200&fltr[]=wmi|/watermark.png|C|100'));
            $new_tag = preg_replace('/src=\"(.*?)\"/',"src='$new_link'", $tag);
            $content = str_replace($tag, $new_tag, $content);
        }        
    }
    echo $content;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question