From the picture processing class in the CMS of Weaving dream, from the weaving Dream cms Picture _php Tutorial

Source: Internet
Author: User
Tags imagecopy imagejpeg

From the picture processing class in the Weaving dream CMS, from the Dream CMS picture


The examples in this paper describe the image processing classes from the CMS. Share to everyone for your reference. Specific as follows:

<?php if (!defined (' Dedeinc ')) exit (' Dedecms ');/** * Image Processing Class * * @version $Id: image.class.php 1 18:10 July 5, 2010 Z Tianya $ * @package dedecms.libraries * @copyright Copyright (c) 2007-2010, Desdev, Inc. * @license http://help.dedecms.com/ usersguide/license.html * @link http://www.dedecms.com */class image{var $attachinfo; var $targetfile;//Picture path var $imag Ecreatefromfunc; var $imagefunc; var $attach; var $animatedgif; var $watermarkquality; var $watermarktext; var $thumbstatus; var $watermarkstatus; Destructors, compatible with PHP4 function image ($targetfile, $cfg _thumb, $cfg _watermarktext, $photo _waterpos, $photo _diaphaneity, $photo _wheight, $photo _wwidth, $cfg _watermarktype, $photo _marktrans, $trueMarkimg, $attach = Array ()) {$this->__construct ($targetfile, $cfg _thumb, $cfg _watermarktext, $photo _waterpos, $photo _diaphaneity, $photo _wheight, $photo _wwidth, $ Cfg_watermarktype, $photo _marktrans, $trueMarkimg, $attach); }//destructor function __construct ($targetfile, $cfg _thumb, $cfg _watermarktext, $photo _waterpos, $photo _diaphaneity, $photo _wheight, $photo _wwidth, $cfg _watermarktype, $photo _marktrans,$  Truemarkimg, $attach = Array ()) {$this->thumbstatus = $cfg _thumb;  $this->watermarktext = $cfg _watermarktext;  $this->watermarkstatus = $photo _waterpos;  $this->watermarkquality = $photo _marktrans;  $this->watermarkminwidth = $photo _wwidth;  $this->watermarkminheight = $photo _wheight;  $this->watermarktype = $cfg _watermarktype;  $this->watermarktrans = $photo _diaphaneity;  $this->animatedgif = 0;  $this->targetfile = $targetfile;  $this->attachinfo = @getimagesize ($targetfile);  $this->attach = $attach; Switch ($this->attachinfo[' mime ') {case ' image/jpeg ': $this->imagecreatefromfunc = function_exists (' Imagecrea Tefromjpeg ')?    ' Imagecreatefromjpeg ': '; $this->imagefunc = function_exists (' imagejpeg ')?    ' imagejpeg ': ';   Break Case ' image/gif ': $this->imagecreatefromfunc = function_exists (' imagecreatefromgif ')? 'Imagecreatefromgif ': '; $this->imagefunc = function_exists (' imagegif ')?    ' Imagegif ': ';   Break Case ' image/png ': $this->imagecreatefromfunc = function_exists (' imagecreatefrompng ')?    ' Imagecreatefrompng ': '; $this->imagefunc = function_exists (' imagepng ')?    ' Imagepng ': ';  Break }//a function of match type does not exist $this->attach[' size ' = Empty ($this->attach[' size ')?  @filesize ($targetfile): $this->attach[' size ';   if ($this->attachinfo[' mime '] = = ' Image/gif ') {$fp = fopen ($targetfile, ' RB ');   $targetfilecontent = Fread ($fp, $this->attach[' size ');   Fclose ($FP); $this->animatedgif = Strpos ($targetfilecontent, ' NETSCAPE2.0 ') = = = False?  0:1; }}/** * Generate thumbnails * * @access public * @param int $thumbwidth picture width * @param int $thumbheight picture height * @param int $pre View Preview * @return void */function thumb ($thumbwidth, $thumbheight, $preview = 0) {$this->thumb_gd ($thumbwidth, $   Thumbheight, $preview); if ($this->thumbstatus = = 2 &AMP;&Amp   $this->watermarkstatus) {$this->image ($this->targetfile, $this->attach);  $this->attach[' size '] = filesize ($this->targetfile);  }}/** * Picture watermark * * @access public * @param int $preview preview * @return void */function watermark ($preview = 0) { if ($this->watermarkminwidth && $this->attachinfo[0] <= $this->watermarkminwidth && $  This->watermarkminheight && $this->attachinfo[1] <= $this->watermarkminheight) {return; } $this-&GT;WATERMARK_GD ($preview); /** * Use GD to generate thumbnails * * @access public * @param int $thumbwidth picture width * @param int $thumbheight picture height * @param int $p Review Preview * @return void */function thumb_gd ($thumbwidth, $thumbheight, $preview = 0) {if ($this->thumbstatus &am p;& function_exists (' Imagecreatetruecolor ') && function_exists (' imagecopyresampled ') &&   Function_exists (' imagejpeg ')) {$imagecreatefromfunc = $this->imagecreatefromfunc; $imagefunc = $thiS->thumbstatus = = 1?   ' imagejpeg ': $this->imagefunc;   List ($imagewidth, $imageheight) = $this->attachinfo; if (! $this->animatedgif && ($imagewidth >= $thumbwidth | | $imageheight >= $thumbheight)) {$attach _ph    Oto = $imagecreatefromfunc ($this->targetfile);    $x _ratio = $thumbwidth/$imagewidth;    $y _ratio = $thumbheight/$imageheight;     if (($x _ratio * $imageheight) < $thumbheight) {$thumb [' height '] = ceil ($x _ratio * $imageheight);    $thumb [' width '] = $thumbwidth;     } else {$thumb [' width '] = ceil ($y _ratio * $imagewidth);    $thumb [' height '] = $thumbheight; } $targetfile =! $preview? ($this->thumbstatus = = 1? $this->targetfile.    Thumb.jpg ': $this->targetfile): './watermark_tmp.jpg ';    $thumb _photo = Imagecreatetruecolor ($thumb [' width '], $thumb [' height ']); Imagecopyresampled ($thumb _photo, $attach _photo, 0, 0, 0, 0, $thumb [' width '], $thumb [' height '], $imagewidth, $    ImageHeight); if ($this->attachinFo[' mime '] = = ' Image/jpeg ') {$imagefunc ($thumb _photo, $targetfile, 100);    } else {$imagefunc ($thumb _photo, $targetfile); } $this->attach[' thumb ' = $this->thumbstatus = = 1?   1:0; }}}/** * watermark with GD * * @access public * @param int $preview preview * @return void */function watermark_gd ($previe w = 0) {if ($this->watermarkstatus && function_exists (' imagecopy ') && function_exists (' Imagealphablending ') && function_exists (' Imagecopymerge ') {$imagecreatefunc = $this   Imagecreatefromfunc;   $imagefunc = $this->imagefunc;   List ($imagewidth, $imageheight) = $this->attachinfo; if ($this->watermarktype < 2) {$watermark _file = $this->watermarktype = = 1? Dededata. ' /mark/mark.png ': Dededata. '    /mark/mark.gif ';    $watermarkinfo = @getimagesize ($watermark _file); $watermark _logo = $this->watermarktype = = 1?    @imagecreatefrompng ($watermark _file): @imagecreatefromgif ($watermark _file); if (! $waTermark_logo) {return;   } list ($logowidth, $logoheight) = $watermarkinfo; } else {$box = @imagettfbbox ($this->watermarktext[' size '], $this->watermarktext[' angle '), $this->watermar    ktext[' Fontpath '), $this->watermarktext[' text ']);    $logowidth = Max ($box [2], $box [4])-min ($box [0], $box [6]);    $logoheight = Max ($box [1], $box [3])-min ($box [5], $box [7]);    $ax = min ($box [0], $box [6]) *-1;   $ay = min ($box [5], $box [7]) *-1;   } $wmwidth = $imagewidth-$logowidth;   $wmheight = $imageheight-$logoheight; if (($this->watermarktype < 2 && is_readable ($watermark _file) | | $this->watermarktype = 2) && $    Wmwidth > && $wmheight > && $this->animatedgif) {switch ($this->watermarkstatus)      {Case 1: $x = +5;      $y = +5;     Break      Case 2: $x = ($imagewidth-$logowidth)/2;      $y = +5;     Break      Case 3: $x = $imagewidth-$logowidth-5;    $y = +5;  Break      Case 4: $x = +5;      $y = ($imageheight-$logoheight)/2;     Break      Case 5: $x = ($imagewidth-$logowidth)/2;      $y = ($imageheight-$logoheight)/2;     Break      Case 6: $x = $imagewidth-$logowidth-5;      $y = ($imageheight-$logoheight)/2;     Break      Case 7: $x = +5;      $y = $imageheight-$logoheight-5;     Break      Case 8: $x = ($imagewidth-$logowidth)/2;      $y = $imageheight-$logoheight-5;     Break      Case 9: $x = $imagewidth-$logowidth-5;      $y = $imageheight-$logoheight-5;    Break    } $dst _photo = @imagecreatetruecolor ($imagewidth, $imageheight);    $target _photo = $imagecreatefunc ($this->targetfile);    Imagecopy ($dst _photo, $target _photo, 0, 0, 0, 0, $imagewidth, $imageheight);    if ($this->watermarktype = = 1) {imagecopy ($dst _photo, $watermark _logo, $x, $y, 0, 0, $logowidth, $logoheight); } elseif ($this->watermarktype = = 2) {if ($this->watermarktext[' Shadowx ' | | $this->watermarktext[' shadowy ') && $this->watermarktext[' Shadowcolor ') {$shadowcolorrgb = Explod      E (', ', $this->watermarktext[' Shadowcolor '));      $shadowcolor = Imagecolorallocate ($dst _photo, $shadowcolorrgb [0], $shadowcolorrgb [1], $shadowcolorrgb [2]); Imagettftext ($dst _photo, $this->watermarktext[' size ', $this->watermarktext[' angle '], $x + $ax + $this->wate rmarktext[' shadowx ', $y + $ay + $this->watermarktext[' shadowy '), $shadowcolor, $this->watermarktext[' Fontpath '     ], $this->watermarktext[' text ']);     } $colorrgb = Explode (', ', $this->watermarktext[' color ');     $color = Imagecolorallocate ($dst _photo, $colorrgb [0], $colorrgb [1], $colorrgb [2]); Imagettftext ($dst _photo, $this->watermarktext[' size ', $this->watermarktext[' angle '], $x + $ax, $y + $ay, $color    , $this->watermarktext[' Fontpath '), $this->watermarktext[' text ']); } else {imagealphablending ($waTermark_logo, True);    Imagecopymerge ($dst _photo, $watermark _logo, $x, $y, 0, 0, $logowidth, $logoheight, $this->watermarktrans); } $targetfile =! $preview?    $this->targetfile: './watermark_tmp.jpg ';     if ($this->attachinfo[' mime '] = = ' Image/jpeg ') {$imagefunc ($dst _photo, $targetfile, $this->watermarkquality);    } else {$imagefunc ($dst _photo, $targetfile);   } $this->attach[' size ' = filesize ($this->targetfile); }}}}//end Class

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/1044854.html www.bkjia.com true http://www.bkjia.com/PHPjc/1044854.html techarticle From the picture processing class in the Weaving dream CMS, from the Dream CMS Picture This article describes a picture processing class from the Dream cms. Share to everyone for your reference. as follows: PHP if (!de ...

  • Related Article

    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.