05-04-26, 01:10 PM
PHP كود :
<?php
// تحميل الصورة باستخدام cURL
function downloadImage($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
curl_setopt($ch, CURLOPT_REFERER, $url);
$data = curl_exec($ch);
if(curl_errno($ch)){
curl_close($ch);
return false;
}
curl_close($ch);
return $data;
}
// ختم الصورة
function watermark($filePath, $ext, $logo){
if ($ext == 'jpg' || $ext == 'jpeg') {
$img = @imagecreatefromjpeg($filePath);
} elseif ($ext == 'png') {
$img = @imagecreatefrompng($filePath);
} elseif ($ext == 'gif') {
$img = @imagecreatefromgif($filePath);
} elseif ($ext == 'webp') {
$img = @imagecreatefromwebp($filePath);
} else {
return false;
}
if (!$img) return false;
$logoImg = imagecreatefrompng($logo);
$imgW = imagesx($img);
$imgH = imagesy($img);
$logoW = imagesx($logoImg);
$logoH = imagesy($logoImg);
// مكان الشعار (أسفل اليمين)
$x = $imgW - ($logoW + 10);
$y = $imgH - ($logoH + 10);
imagealphablending($img, true);
imagesavealpha($img, true);
imagecopy($img, $logoImg, $x, $y, 0, 0, $logoW, $logoH);
// حفظ كـ JPG
imagejpeg($img, $filePath, 90);
imagedestroy($img);
imagedestroy($logoImg);
return true;
}
// عند الإرسال
if($_POST){
$url = trim($_POST['url']);
if(!$url){
die("❌ أدخل رابط الصورة");
}
// تحميل الصورة
$imageData = downloadImage($url);
if(!$imageData){
die("❌ فشل تحميل الصورة (الرابط محمي أو غير صحيح)");
}
// استخراج الامتداد
$ext = strtolower(pathinfo(parse_url($url, PHP_URL_PATH), PATHINFO_EXTENSION));
if(!$ext){
$ext = "jpg";
}
// اسم جديد
$name = time() . ".jpg";
$filePath = "uploads/" . $name;
// حفظ الصورة
file_put_contents($filePath, $imageData);
// ختم الصورة
watermark($filePath, $ext, "logo/logo.png");
echo "✅ تم بنجاح: <a href='$filePath' target='_blank'>عرض الصورة</a>";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>رفع وختم الصور</title>
</head>
<body>
<h3>تحميل وختم صورة من رابط</h3>
<form method="post">
<input type="text" name="url" style="width:400px" placeholder="ضع رابط الصورة هنا">
<input type="submit" value="تحميل وختم">
</form>
</body>
</html>


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