当前位置: 首页 > news >正文

汽车之家这样的网站怎么做地推网app推广平台

汽车之家这样的网站怎么做,地推网app推广平台,怎么使自己做的网站有音乐,c 网站登录验证码怎么做演示环境: 1、windows10 2、phpstudy 3、php7.4 一、案例演示: 二、素材准备 1、准备一张原始图片 2、准备一张水印图片(透明底图的最好) 3、字体库(windows系统自带的字体库,路径在:C:\Window…

演示环境:
1、windows10
2、phpstudy
3、php7.4

一、案例演示:

在这里插入图片描述
在这里插入图片描述

二、素材准备

1、准备一张原始图片
2、准备一张水印图片(透明底图的最好)
3、字体库(windows系统自带的字体库,路径在:C:\Windows\Fonts)
4、开启GD库
在这里插入图片描述
在这里插入图片描述

三、图片添加水印

1、文字水印封装类 FontWatermark.class.php

<?phpclass FontWatermark
{private $sourceImagePath;private $fontPath;private $fontSize;private $watermarkText;private $outputImagePath;public function __construct($sourceImagePath, $fontPath, $fontSize, $watermarkText, $outputImagePath){$this->sourceImagePath = $sourceImagePath;$this->fontPath = realpath($fontPath);  // 获取字体文件的绝对路径$this->fontSize = $fontSize;$this->watermarkText = $watermarkText;$this->outputImagePath = $outputImagePath;}public function addFontWatermark(){// 加载源图片$sourceImage = imagecreatefromjpeg($this->sourceImagePath);if (!$sourceImage) {die('无法加载源图片');}// 获取源图片的宽高$sourceWidth = imagesx($sourceImage);$sourceHeight = imagesy($sourceImage);// 确保字体文件存在if (!file_exists($this->fontPath)) {die('字体文件不存在: ' . $this->fontPath);}// 设置文字颜色 (白色)$white = imagecolorallocate($sourceImage, 255, 255, 255);// 设置文字阴影颜色 (黑色)$black = imagecolorallocate($sourceImage, 0, 0, 0);// 计算文字水印的边界框$textBox = imagettfbbox($this->fontSize, 0, $this->fontPath, $this->watermarkText);if ($textBox === false) {die('无法计算文字边界框');}$textWidth = $textBox[2] - $textBox[0];$textHeight = $textBox[1] - $textBox[7];// 设置文字水印的位置 (左上角)$destX = 10;$destY = $textHeight + 10;// 绘制阴影文字if (imagettftext($sourceImage, $this->fontSize, 0, $destX + 2, $destY + 2, $black, $this->fontPath, $this->watermarkText) === false) {die('无法绘制阴影文字');}// 绘制水印文字if (imagettftext($sourceImage, $this->fontSize, 0, $destX, $destY, $white, $this->fontPath, $this->watermarkText) === false) {die('无法绘制水印文字');}// 保存加水印后的图片if (!imagejpeg($sourceImage, $this->outputImagePath)) {die('无法保存加水印后的图片');}// 释放内存imagedestroy($sourceImage);echo "图片水印已添加并保存到: " . $this->outputImagePath;echo "<br>";echo "<img src='" . $this->outputImagePath . "' alt='文字水印' width='400px;' height='300px;'>";}
}
?>

2、调用文字水印类

<?php
require "FontWatermark.class.php";
// 使用示例
$watermark = new FontWatermark('1111.jpg',                // 源图片路径'msyh.ttc', // 字体路径80,                        // 字体大小'测试水印',                 // 水印文字'font_watermark.jpg' // 输出图片路径
);$watermark->addFontWatermark();?>

四、图片添加图片水印

1、图片水印封装类 WatermarkImage.class.php

<?php
class WatermarkImage
{private $sourceImagePath;private $watermarkImagePath;private $outputImagePath;private $sourceImage;private $watermarkImage;public function __construct($sourceImagePath, $watermarkImagePath, $outputImagePath){$this->sourceImagePath = $sourceImagePath;$this->watermarkImagePath = $watermarkImagePath;$this->outputImagePath = $outputImagePath;}private function loadImages(){// 加载源图片$this->sourceImage = @imagecreatefromjpeg($this->sourceImagePath);if (!$this->sourceImage) {die('无法加载源图片: ' . $this->sourceImagePath);}// 加载水印图片$this->watermarkImage = @imagecreatefrompng($this->watermarkImagePath);if (!$this->watermarkImage) {imagedestroy($this->sourceImage);die('无法加载水印图片: ' . $this->watermarkImagePath);}}private function addWatermark(){// 获取源图片和水印图片的宽高$sourceWidth = imagesx($this->sourceImage);$sourceHeight = imagesy($this->sourceImage);$watermarkWidth = imagesx($this->watermarkImage);$watermarkHeight = imagesy($this->watermarkImage);// 计算水印位置(右下角)$destX = $sourceWidth - $watermarkWidth - 10; // 右边距10像素$destY = $sourceHeight - $watermarkHeight - 10; // 底边距10像素// 将水印图片合并到源图片上imagecopy($this->sourceImage, $this->watermarkImage, $destX, $destY, 0, 0, $watermarkWidth, $watermarkHeight);}private function saveImage(){// 保存加水印后的图片if (!imagejpeg($this->sourceImage, $this->outputImagePath)) {imagedestroy($this->sourceImage);imagedestroy($this->watermarkImage);die('无法保存加水印后的图片: ' . $this->outputImagePath);}}private function cleanup(){// 释放内存imagedestroy($this->sourceImage);imagedestroy($this->watermarkImage);}public function applyWatermark(){$this->loadImages();$this->addWatermark();$this->saveImage();$this->cleanup();echo "图片水印已添加并保存到: " . $this->outputImagePath;echo "<br>";echo "<img src='" . $this->outputImagePath . "' alt='图片水印' width='400px;' height='300px;'>";}
}?>

2、调用图片水印类

<?php
require "WatermarkImage.class.php";
// 使用示例
$sourceImagePath = '1111.jpg';
$watermarkImagePath = 'shuiyin.png';
$outputImagePath = 'image_watermark.jpg';$watermarker = new WatermarkImage($sourceImagePath, $watermarkImagePath, $outputImagePath);
$watermarker->applyWatermark();?>

五、压缩图片

1、缩略图封装类 ImageResizer

<?phpclass ImageResizer
{private $sourceImage;private $sourceWidth;private $sourceHeight;public function __construct($sourceImagePath){$this->loadImage($sourceImagePath);}private function loadImage($path){if (!file_exists($path)) {throw new Exception("File does not exist: $path");}$this->sourceImage = imagecreatefromjpeg($path);if (!$this->sourceImage) {throw new Exception("Failed to load image: $path");}$this->sourceWidth = imagesx($this->sourceImage);$this->sourceHeight = imagesy($this->sourceImage);}public function resize($width, $height, $outputPath){$thumb = imagecreatetruecolor($width, $height);imagecopyresampled($thumb,$this->sourceImage,0,0,0,0,$width,$height,$this->sourceWidth,$this->sourceHeight);if (!imagejpeg($thumb, $outputPath)) {throw new Exception("Failed to save thumbnail to: $outputPath");}imagedestroy($thumb);}public function __destruct(){imagedestroy($this->sourceImage);}
}?>

2、调用缩略图类

<?php
require "Resizer.class.php";// 使用示例
try {$sourceImagePath = 'E:\test\Resizer\222.jpg';// $outputImagePath = 'E:\test\Resizer\222_resier.jpg';$outputImagePath = '222_resier.jpg';$width = 200;$height = 200;$resizer = new ImageResizer($sourceImagePath);$resizer->resize($width, $height, $outputImagePath);echo "缩略图创建在网站目录下,图片名称: $outputImagePath";echo "<br>";echo "<img src='$outputImagePath' alt='缩略图'>";
} catch (Exception $e) {echo "错误: " . $e->getMessage();
}
?>

说明:更多复杂的水印功能可以基于此脚本扩展

http://www.dinnco.com/news/68374.html

相关文章:

  • 网站第三方微信登陆怎么做的软文标题和内容
  • 有没有专业做网站的白云区新闻
  • 网站建设色调的企业高管培训课程有哪些
  • 微信网站开发报价表百度有哪些产品
  • 推广普通话宣传内容北京seo培训
  • 南宁哪个公司做网站好搜索引擎优化培训
  • 网站建设前期准备方案北海seo快速排名
  • 北京移动端网站今日财经最新消息
  • 延边网站开发depawo最近一周新闻大事摘抄2022年
  • 温州网站 公司软文推广去哪个平台好
  • 济宁软件开发网站建设网站批量查询
  • wordpress 站内资讯口碑营销成功案例
  • 桌子上做嗯啊干爹网站北京网站优化合作
  • 深圳网站制作07551760关键词排名查询
  • wordpress 国内视频网站石家庄关键词优化平台
  • 做照片书的网站好百度指数移动版
  • 网站上线稳定后工作网站推广的渠道有
  • 新网站怎么做谷歌推广呢站长工具5g
  • 一个人做两个博客网站线上推广100种方式
  • 空间租用网站模板怎么推广游戏代理赚钱
  • 网站建设维护培训seo网站推广是什么
  • 今天的西安今日头条seo外包公司需要什么
  • 如何办理浙江省网站备案密码重置和备案注销搜索引擎优化名词解释
  • 网站备案幕布申请海南网站制作公司
  • 阿里云服务器做网站多少钱seo推广是什么意思呢
  • 北京网站设计与制作公司在线葡京在线葡京
  • 美国室内设计网站大全百度优化教程
  • 电脑版网页灵宝seo公司
  • 山西建设网站百度惠生活推广怎么收费
  • 建美食网站有哪些原因做小程序公司哪家好