04-04-26, 06:15 PM
تعديل دالة AddWatermark
احتمال اخر اذا ما ضبط معك الاول
PHP كود :
function AddWatermark($imagePath, $text) {
$data = @file_get_contents($imagePath);
if (!$data) return;
$img = @imagecreatefromstring($data);
if (!$img) {
return; // لا تخرب الصورة إذا فشل
}
$width = imagesx($img);
$height = imagesy($img);
$color = imagecolorallocatealpha($img, 255, 255, 255, 50);
$x = $width - 120;
$y = $height - 15;
imagestring($img, 3, $x, $y, $text, $color);
imagejpeg($img, $imagePath, 90);
imagedestroy($img);
}
احتمال اخر اذا ما ضبط معك الاول
PHP كود :
function AddWatermark($imagePath, $text) {
$ext = strtolower(pathinfo($imagePath, PATHINFO_EXTENSION));
if ($ext == 'jpg' || $ext == 'jpeg') {
$img = @imagecreatefromjpeg($imagePath);
} elseif ($ext == 'png') {
$img = @imagecreatefrompng($imagePath);
} elseif ($ext == 'gif') {
$img = @imagecreatefromgif($imagePath);
} elseif ($ext == 'webp') {
$img = @imagecreatefromwebp($imagePath);
} else {
return;
}
if (!$img) return;
$width = imagesx($img);
$height = imagesy($img);
$color = imagecolorallocatealpha($img, 255, 255, 255, 50);
$x = $width - 120;
$y = $height - 15;
imagestring($img, 3, $x, $y, $text, $color);
if ($ext == 'jpg' || $ext == 'jpeg') {
imagejpeg($img, $imagePath, 90);
} elseif ($ext == 'png') {
imagepng($img, $imagePath);
} elseif ($ext == 'gif') {
imagegif($img, $imagePath);
} elseif ($ext == 'webp') {
imagewebp($img, $imagePath);
}
imagedestroy($img);
}


![[صورة مرفقة: 177461173141861.gif]](https://up6.cc/2026/03/177461173141861.gif)