php 批量给图片加水印代码
php 批量给图片加水印代码 我们经常会碰到要对大量的图片进行一次性增加水印,这就会碰到批量增加图片水印功能了,我们为你提供一款php批量增加水印的功能。
php教程 批量给图片加水印代码
我们经常会碰到要对大量的图片进行一次性增加水印,这就会碰到批量增加图片水印功能了,我们为你提供一款php批量增加水印的功能。
//config.php
//=================================用户配置区=================================
$per=1; //每次处理的图片数目
$dir1='img'; //输入目录
$dir2='img2'; //输出目录 输出图片会保存于$dir2/$dir1目录下面
$mark_img='www.bKjia.c0m.gif'; //水印图片
$mark_text=''; //水印文字内容 【不支持中文】
$mark_text_size=25; //水印文字大小
$mark_pos=5; //水印位置,0为随机,1为顶端居左,2为顶端居中,3为顶端居右,4为中部居左,5为中部居中,6为中部居右,7为底端居左,8为底端居中,9为底端居右;
//=================================用户配置区【结束】=================================
//mark.php加水印文件
function go( $url, $t = 0 )
{
exit( ( "" );
}function imagewatermark( $product_img, $waterpos = 0, $waterimage = "", $watertext = "", $textfont = 25, $textcolor = "#ff0000", $newdir = "marked" )
{
echo "正在处理图片:".$product_img."
";
$iswaterimage = false;
$formatmsg = "暂不支持该文件格式,请用图片处理软件将图片转换为gif、jpg、png格式。";
if ( !empty( $waterimage ) && file_exists( $waterimage ) )
{
$iswaterimage = true;
$water_info = getimagesize( $waterimage );
$water_w = $water_info[0];
$water_h = $water_info[1];
switch ( $water_info[2] )
{
case 1 :
$water_im = imagecreatefromgif( $waterimage );
break;
case 2 :
$water_im = imagecreatefromjpeg( $waterimage );
break;
case 3 :
$water_im = imagecreatefrompng( $waterimage );
break;
default :
echo $formatmsg;
return;
}
}
if ( !empty( $product_img ) && file_exists( $product_img ) )
{
$ground_info = getimagesize( $product_img );
$ground_w = $ground_info[0];
$ground_h = $ground_info[1];
switch ( $ground_info[2] )
{
case 1 :
$ground_im = imagecreatefromgif( $product_img );
break;
case 2 :
$ground_im = imagecreatefromjpeg( $product_img );
break;
case 3 :
$ground_im = imagecreatefrompng( $product_img );
break;
default :
echo $formatmsg;
return;
}
}
else
{
exit( "需要加水印的图片不存在!" );
}
if ( $iswaterimage )
{
$w = $water_w;
$h = $water_h;
$label = "图片的";
}
else
{
$temp = @imagettfbbox( @ceil( $textfont * 2.5 ), 0, "arial.ttf", $watertext );
$w = $temp[2] - $temp[6];
$h = $temp[3] - $temp[7];
unset( $temp );
$label = "文字区域";
}
if ( $ground_w {
echo "需要加水印的图片的长度或宽度比水印".$label."还小,无法生成水印!";
}
else
{
switch ( $waterpos )
{
case 0 :
$posx = rand( 0, $ground_w - $w );
$posy = rand( 0, $ground_h - $h );
break;
case 1 :
$posx = 0;
$posy = 0;
break;
case 2 :
$posx = ( $ground_w - $w ) / 2;
$posy = 0;
break;
case 3 :
$posx = $ground_w - $w;
$posy = 0;
break;
case 4 :
$posx = 0;
$posy = ( $ground_h - $h ) / 2;
break;
case 5 :
$posx = ( $ground_w - $w ) / 2;
$posy = ( $ground_h - $h ) / 2;
break;
case 6 :
$posx = $ground_w - $w;
$posy = ( $ground_h - $h ) / 2;
break;
case 7 :
$posx = 0;
$posy = $ground_h - $h;
break;
case 8 :
$posx = ( $ground_w - $w ) / 2;
$posy = $ground_h - $h;
break;
case 9 :
$posx = $ground_w - $w;
$posy = $ground_h - $h;
break;
default :
$posx = rand( 0, $ground_w - $w );
$posy = rand( 0, $ground_h - $h );
break;
}
imagealphablending( $ground_im, true );
imagecopyresampled($ground_im, $water_im,0,0, $posx, $posy, 0, 0, $water_w, $water_h);
if ( $iswaterimage )
{
imagecopymerge( $ground_im, $water_im, $posx, $posy, 0, 0, $water_w, $water_h,35 );
}
else
{
if ( !empty( $textcolor ) && strlen( $textcolor ) == 7 )
{
$r = hexdec( substr( $textcolor, 1, 2 ) );
$g = hexdec( substr( $textcolor, 3, 2 ) );
$b = hexdec( substr( $textcolor, 5 ) );
}
else
{
exit( "水印文字颜色格式不正确!" );
}
imagestring( $ground_im, $textfont, $posx, $posy, $watertext, imagecolorallocate( $ground_im, $r, $g, $b ) ,35);
}
switch ( $ground_info[2] )
{
case 1 :
imagegif( $ground_im, $newdir."/".$product_img );
break;
case 2 :
imagejpeg( $ground_im, $newdir."/".$product_img );
break;
case 3 :
imagepng( $ground_im, $newdir."/".$product_img );
break;
default :
echo $errormsg;
}
if ( isset( $water_info ) )
{
unset( $water_info );
}
if ( isset( $water_im ) )
{
imagedestroy( $water_im );
}
unset( $ground_info );
imagedestroy( $ground_im );
unset( $water_im );
unset( $ground_im );
}
}set_time_limit( 0 );
include( "config.php" );
if ( $_get[id] )
{
$id = $_get[id];
}
else
{
$id = 1;
}
if ( !is_dir( $dir2."/".$dir1 ) )
{
mkdir( $dir2."/".$dir1, 511 );
}
$ti = 0;
$dir = opendir( $dir1 );
while ( $file = readdir( $dir ) )
{
if ( $file == "." || $file == ".." )
{
}
else
{
++$ti;
if ( $ti {
}
else
{
if ( ( $id - 1 ) * $per {
imagewatermark( $dir1."/".$file, $mark_pos, $mark_img, $mark_text, $mark_text_size, "#ff0000", $dir2 );
}
if ( $id * $per {
closedir( $dir );
go( "mark.php?id=".( $id + 1 ) );
}
}
}
}
echo "

Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

AI Hentai Generator
Générez AI Hentai gratuitement.

Article chaud

Outils chauds

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Sujets chauds

Dans ce chapitre, nous comprendrons les variables d'environnement, la configuration générale, la configuration de la base de données et la configuration de la messagerie dans CakePHP.

PHP 8.4 apporte plusieurs nouvelles fonctionnalités, améliorations de sécurité et de performances avec une bonne quantité de dépréciations et de suppressions de fonctionnalités. Ce guide explique comment installer PHP 8.4 ou mettre à niveau vers PHP 8.4 sur Ubuntu, Debian ou leurs dérivés. Bien qu'il soit possible de compiler PHP à partir des sources, son installation à partir d'un référentiel APT comme expliqué ci-dessous est souvent plus rapide et plus sécurisée car ces référentiels fourniront les dernières corrections de bogues et mises à jour de sécurité à l'avenir.

Pour travailler avec la date et l'heure dans cakephp4, nous allons utiliser la classe FrozenTime disponible.

Pour travailler sur le téléchargement de fichiers, nous allons utiliser l'assistant de formulaire. Voici un exemple de téléchargement de fichiers.

Dans ce chapitre, nous allons apprendre les sujets suivants liés au routage ?

CakePHP est un framework open source pour PHP. Il vise à faciliter grandement le développement, le déploiement et la maintenance d'applications. CakePHP est basé sur une architecture de type MVC à la fois puissante et facile à appréhender. Modèles, vues et contrôleurs gu

Visual Studio Code, également connu sous le nom de VS Code, est un éditeur de code source gratuit – ou environnement de développement intégré (IDE) – disponible pour tous les principaux systèmes d'exploitation. Avec une large collection d'extensions pour de nombreux langages de programmation, VS Code peut être c

Le validateur peut être créé en ajoutant les deux lignes suivantes dans le contrôleur.
