تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
طلب اضافة ختم الصور لهذا الكود
#43
PHP كود :
<?php

// تحميل الصورة باستخدام cURL
function downloadImage($url){
    $ch curl_init($url);
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
    curl_setopt($chCURLOPT_USERAGENT"Mozilla/5.0");
    curl_setopt($chCURLOPT_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($imgtrue);
    imagesavealpha($imgtrue);

    imagecopy($img$logoImg$x$y00$logoW$logoH);

    // حفظ كـ JPG
    imagejpeg($img$filePath90);

    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($urlPHP_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]
الرد }}}
تم الشكر بواسطة: nnnjk , nnnjk


الردود في هذا الموضوع
RE: طلب اضافة ختم الصور لهذا الكود - بواسطة Amir_Alzubidy - 05-04-26, 01:10 PM


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم