recherche
  • Se connecter
  • S'inscrire
Réinitialisation du mot de passe réussie

Suivez les projets qui vous intéressent et découvrez les dernières actualités les concernant.

Image de sortie du didacticiel de filigrane de texte de développement PHP

Image de sortie

<?php
     /*打开图片*/
     //1.配置图片路径(填入你的图片路径)
     $src="https://img.php.cn/upload/course/000/000/004/581454f755fb1195.jpg";
     //获取图片信息
     $info = getimagesize($src);
     //通过图像的编号来获取图像的类型
     $type=image_type_to_extension($info[2],false);
     //在内存中创建一个和我们图像类型一样的图像
     $fun = "imagecreatefrom{$type}";
     //把图片复制到我们的内存中
     $image=$fun($src);
    /*操作图片*/
     //设置字体的路径
     $font="/tpl/Index/Static/css/img/fonts/Christmas.ttf";
     //添加内容
     $content="欢迎来到php中文网";
     //设置字体的颜色和透明度
     $col=imagecolorallocatealpha($image,255,255,255,30);
     //写入文字
     imagettftext($image,20,0,20,30,$col,$font,$content);
     /*输出图片*/
     //浏览器输出
     header("Content-type:".$info['mime']);
     $func="image{$type}";
     $func($image);
     //保存图片
     $func($image,'FFF.'.$type);
     /*销毁图片*/
     imagedestroy($image);
 ?>
rrree

Définissez une variable $func.

Sortie directement depuis le navigateur.

Ou enregistrez la sortie de l'image avec un nom personnalisé.

De cette façon, l'ajout d'un filigrane de texte à l'image est terminé.

nouveau fichier
<?php /*打开图片*/ //1.配置图片路径(填入你的图片路径) $src="https://img.php.cn/upload/course/000/000/004/581454f755fb1195.jpg"; //获取图片信息 $info = getimagesize($src); //通过图像的编号来获取图像的类型 $type=image_type_to_extension($info[2],false); //在内存中创建一个和我们图像类型一样的图像 $fun = "imagecreatefrom{$type}"; //把图片复制到我们的内存中 $image=$fun($src); /*操作图片*/ //设置字体的路径 $font="/tpl/Index/Static/css/img/fonts/Christmas.ttf"; //添加内容 $content="欢迎来到php中文网"; //设置字体的颜色和透明度 $col=imagecolorallocatealpha($image,255,255,255,30); //写入文字 imagettftext($image,20,0,20,30,$col,$font,$content); /*输出图片*/ //浏览器输出 header("Content-type:".$info['mime']); $func="image{$type}"; $func($image); //保存图片 $func($image,'FFF.'.$type); /*销毁图片*/ imagedestroy($image); ?>
Réinitialiser le code
Opération automatique
soumettre
Aperçu Clear