PHP Imagick two ways to expand a composite image

Source: Internet
Author: User
Method One: Compositeimages

/** * Function: Compositing picture * @param string $output _url picture Save path * @param string $img _type picture Save type *       @param integral $line Display the number of pictures per line * @param array $logo _info each image to be synthesized (requires all dimensions unified) * @param array $img _list The absolute path of the image to be synthesized * * @return void */Public function Generate ($output _url, $img _type, $line _num,        $logo _info, $img _list=array ()) {//Calculate how many lines of the picture are $lines = Ceil (count ($img _list)/$line _num);        $BG _width = ($logo _info[' width ') + $logo _info[' line_width ']) * $line _num;        $BG _height = ($logo _info[' height ') + $logo _info[' line_height ']) * $lines;        Build Canvas $canvas = new Imagick ();        $canvas->newimage ($bg _width, $bg _height, ' White ');        $canvas->setimageformat ($img _type);        $i = $j = 0;            foreach ($img _list as $item) {$im = new Imagick ($item);            $x = $logo _info[' line_width ']*2 + $i * $logo _info[' width ']; $y = $logo _info[' line_height ']*2 + $j * $logo_info[' height '];            $canvas->compositeimage ($im, GetImage (), Imagick::composite_over, $x, $y);            $canvas-Compositeimage ($im, $im->getimagecompose (), $x, $y);                if (($i + 1)% $line _num = = = 0) {$i = 0;            $j + +;            } else {$i + +;            }//Unset ($IM);        $im-Destroy ();        } $canvas->writeimage ($output _url);    Destroyed Objects $canvas, destroy (); }



Method Two: Combineimages

/** * Function: Compositing picture * @param string $output _url picture Save path * @param string $img _type picture Save type *       @param integral $line Display the number of pictures per line * @param array $logo _info each image to be synthesized (requires all dimensions unified) * @param array $img _list The absolute path of the image to be synthesized * * @return void */Public function Generate ($output _url, $img _type, $line _num,        $logo _info, $img _list=array ()) {//Calculate how many lines of the picture are $lines = Ceil (count ($img _list)/$line _num);        $BG _width = ($logo _info[' width ') + $logo _info[' line_width ']) * $line _num;        $BG _height = ($logo _info[' height ') + $logo _info[' line_height ']) * $lines;        Build canvas $canvas = null;        $canvas = new Imagick ();        $canvas-NewImage ($bg _width, $bg _height, ' White ');        $i = $j = 0;            foreach ($img _list as $item) {$im = null;            $im = new Imagick ($item);            $canvas-Readimage ($item);            $canvas-AddImage ($im);      $im, Clear ();      $im-Destroy ();        }//$canvas-flattenimages ();         Combineimages, $canvas (Imagick::channel_all);        $canvas-Writeimage ($output _url);        Destroy Object $canvas Clear ();    $canvas-Destroy (); }

Personally think method two more efficient
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.