摘自织梦CMS中的图片处理类
这篇文章主要介绍了摘自织梦CMS中的图片处理类,通过面向对象的方式较为详细的实现了php针对图片的缩略图生成及水印添加等操作技巧,非常具有实用价值,需要的朋友
本文实例讲述了摘自织梦CMS中的图片处理类。分享给大家供大家参考。具体如下:
__construct($targetfile, $cfg_thumb, $cfg_watermarktext, $photo_waterpos, $photo_diaphaneity, $photo_wheight, $photo_wwidth, $cfg_watermarktype, $photo_marktrans,$trueMarkimg, $attach); } // 析构函数 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('imagecreatefromjpeg') ? '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; }//为空则匹配类型的函数不存在 $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; } } /** * 生成缩略图 * * @access public * @param int $thumbwidth 图片宽度 * @param int $thumbheight 图片高度 * @param int $preview 是否预览 * @return void */ function thumb($thumbwidth, $thumbheight, $preview = 0) { $this->thumb_gd($thumbwidth, $thumbheight, $preview); if($this->thumbstatus == 2 && $this->watermarkstatus) { $this->image($this->targetfile, $this->attach); $this->attach['size'] = filesize($this->targetfile); } } /** * 图片水印 * * @access public * @param int $preview 是否预览 * @return void */ function watermark($preview = 0) { if($this->watermarkminwidth && $this->attachinfo[0] watermarkminwidth && $this->watermarkminheight && $this->attachinfo[1] watermarkminheight) { return ; } $this->watermark_gd($preview); } /** * 使用gd生成缩略图 * * @access public * @param int $thumbwidth 图片宽度 * @param int $thumbheight 图片高度 * @param int $preview 是否预览 * @return void */ function thumb_gd($thumbwidth, $thumbheight, $preview = 0) { if($this->thumbstatus && 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_photo = $imagecreatefromfunc($this->targetfile); $x_ratio = $thumbwidth / $imagewidth; $y_ratio = $thumbheight / $imageheight; if(($x_ratio * $imageheight) 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; } } } /** * 使用gd进行水印 * * @access public * @param int $preview 是否预览 * @return void */ function watermark_gd($preview = 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 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->watermarktext['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 watermarktype == 2) && $wmwidth > 10 && $wmheight > 10 && !$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 = explode(',', $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->watermarktext['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
希望本文所述对大家的php程序设计有所帮助。
,
핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Dreamweaver CMS 스테이션 그룹 실습 공유 최근 몇 년간 인터넷의 급속한 발전으로 인해 웹사이트 구축이 점점 더 중요해지고 있습니다. 여러 웹사이트를 구축할 때 사이트 그룹 기술은 매우 효과적인 방법이 되었습니다. 많은 웹 사이트 구축 도구 중에서 DreamWeaver CMS는 유연성과 사용 용이성으로 인해 많은 웹 사이트 애호가들의 첫 번째 선택이 되었습니다. 이 기사에서는 Dreamweaver CMS 스테이션 그룹에 대한 몇 가지 실제 경험과 일부 특정 코드 예제를 공유하여 스테이션 그룹 기술을 탐색하는 독자에게 도움이 되기를 바랍니다. 1. Dreamweaver CMS 스테이션 그룹이란 무엇입니까? 드림위버 CMS

DreamWeaver cms의 보안은 다음과 같은 이유로 상대적으로 우수합니다: 1. 빠른 취약점 복구 2. CSRF(교차 사이트 스크립팅 공격) 보호 4. SQL 주입 보호 . 코드 감사.

Dreamweaver CMS 시스템에는 요금이 부과되지 않습니다. Dreamweaver CMS는 오픈 소스 콘텐츠 관리 시스템으로, 핵심 코드가 무료로 제공됩니다. 사용자는 최신 버전의 Dreamweaver CMS를 무료로 다운로드하고 관련 기술 지원과 문서를 얻을 수 있습니다. 그러나 사용 중에 사용자는 추가 기능 모듈이나 테마 템플릿을 구매해야 할 수 있으며, 이러한 유료 모듈 및 템플릿 구매 가격은 특정 기능 및 디자인 복잡성에 따라 다릅니다.

제목: DreamWeaver CMS의 보조 디렉터리를 열 수 없는 이유와 해결 방법 분석 Dreamweaver CMS(DedeCMS)는 다양한 웹 사이트 구축에 널리 사용되는 강력한 오픈 소스 콘텐츠 관리 시스템입니다. 그러나 때로는 웹사이트를 구축하는 과정에서 보조 디렉토리를 열 수 없는 상황이 발생할 수 있으며, 이로 인해 웹사이트의 정상적인 작동에 문제가 발생할 수 있습니다. 이 기사에서는 보조 디렉터리를 열 수 없는 가능한 이유를 분석하고 이 문제를 해결하기 위한 구체적인 코드 예제를 제공합니다. 1. 예상 원인 분석: 의사 정적 규칙 구성 문제: 사용 중

Dreamweaver CMS의 데이터베이스 연결 실패에 대한 해결 방법: 1. 데이터베이스 구성을 확인하고 데이터베이스의 관련 정보가 Dreamweaver CMS의 루트 디렉터리에 있는 /data/config.php 파일에 올바르게 설정되어 있는지 확인합니다. 데이터베이스 연결이 성공했는지 테스트하는 간단한 PHP 스크립트를 생성하여 데이터베이스 연결을 테스트합니다. 3. 데이터베이스 서버 상태를 확인하고 DreamWeaver CMS 루트 디렉터리의 /data/config.php 파일에서 데이터베이스 서버 주소를 변경합니다. 4. 네트워크 연결을 확인하세요.

Dreamweaver CMS는 강력한 기능, 친숙한 인터페이스, 사용하기 쉬운 기능을 갖춘 매우 인기 있는 웹 사이트 구축 시스템입니다. 그러나 때로는 특별한 요구 사항을 충족하기 위해 원래 제공했던 기능만으로는 충분하지 않을 수도 있습니다. 이러한 상황에 대응하여 2차 개발을 진행하고 맞춤형 코드를 통해 개인화된 웹사이트 요구를 실현할 수 있습니다. 이 기사에서는 개인화된 웹 사이트 사용자 정의 기술을 활용하는 데 도움이 되는 DreamWeaver CMS의 2차 개발에 대한 몇 가지 비밀을 공유합니다. 1. 홈페이지 캐러셀의 사용자 정의 요구 사항 설명: 원본 Dreamweaver CMS 홈페이지

제목: Dreamweaver CMS의 데이터베이스 파일 삭제 시 주의 사항 인기 있는 웹 사이트 구축 도구인 Dreamweaver CMS의 데이터베이스 파일 삭제는 웹 사이트 유지 관리 시 자주 발생하는 문제 중 하나입니다. 잘못된 데이터베이스 파일 삭제 작업으로 인해 웹사이트 데이터가 손실되거나 웹사이트가 제대로 작동하지 않을 수 있습니다. 따라서 데이터베이스 파일 삭제 작업을 수행할 때는 매우 주의해야 합니다. 다음에서는 Dreamweaver CMS 데이터베이스 파일 삭제 시 주의 사항을 소개하고 데이터베이스 파일을 올바르게 삭제하는 데 도움이 되는 몇 가지 특정 코드 예제를 제공합니다. 참고: 준비하다

죄송합니다. 보안문자 크래킹이나 우회에 대한 정보를 제공할 수 없습니다. 추가 질문이 있거나 도움이 필요하시면 언제든지 알려주시기 바랍니다.
