تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
طلب اضافة ختم الصور لهذا الكود
#45
(05-04-26, 01:27 PM)nnnjk كتب : يعطيك العافيه
بعد سحب الملف من صحيفة الرياض نوع jpg طلعت الصوره سوداء فارغه

PHP كود :
<?php
// دالة تحميل الصورة باستخدام cURL مع Referer و User-Agent
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"https://www.alriyadh.com/"); // مهم للصحف
    $data curl_exec($ch);
    if(curl_errno($ch) || !$data){
        curl_close($ch);
        return false;
    }
    curl_close($ch);
    return $data;
}
// دالة ختم الصورة باستخدام Imagick
function watermark($imageData$logoPath$outputPath){
    $im = new Imagick();
    $im->readImageBlob($imageData);
    // تحويل كل الصور إلى JPG
    $im->setImageFormat("jpeg");
    // تحميل الشعار
    $logo = new Imagick($logoPath);
    $logo->setImageFormat("png");
    // مكان الختم أسفل اليمين
    $x $im->getImageWidth() - $logo->getImageWidth() - 10;
    $y $im->getImageHeight() - $logo->getImageHeight() - 10;
    // دمج الشعار على الصورة
    $im->compositeImage($logoImagick::COMPOSITE_OVER$x$y);
    // حفظ الصورة النهائية
    $im->writeImage($outputPath);
    $im->clear();
    $im->destroy();
    $logo->clear();
    $logo->destroy();
    return true;
}
// عند إرسال النموذج
if($_POST){
    $url trim($_POST['url']);
    if(!$url) die("❌ أدخل رابط الصورة");
    $imageData downloadImage($url);
    if(!$imageData) die("❌ فشل تحميل الصورة (الرابط محمي أو غير صالح)");
    // اسم جديد للملف
    $name time() . ".jpg";
    $filePath "uploads/" $name;
    // تأكد من مجلد uploads موجود وصالح للكتابة
    if(!file_exists("uploads")) mkdir("uploads"0777true);
    // تطبيق الختم وحفظ الصورة
    watermark($imageData"logo/logo.png"$filePath);
    echo "✅ تم تحميل وختم الصورة: <a href='$filePath' target='_blank'>عرض الصورة</a>";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>تحميل وختم الصور باستخدام Imagick</title>
</head>
<body>
<h3>تحميل وختم صورة من رابط</h3>
<form method="post">
<input type="text" name="url" style="width:400px" placeholder="ضع رابط الصورة هنا">
<input type="submit" value="تحميل وختم">
</form>
</body>
</html> 

[*]يدعم كل الصور: JPG، PNG، GIF، WEBP، ويحولها إلى JPG
[*]يمنع ظهور الصور سوداء (باستخدام Imagick بدل GD)
[*]يختم الصور باستخدام شعار PNG أسفل اليمين
[*]يدعم روابط الصحف و المواقع المحمية بـ Referer
بغض النظر عن حجم الصورة أو نوع ترميزها

ملاحظة مهمة
تأكد من وجود مجلد uploads/ وصلاحياته 755 أو 777
[*]تأكد من وجود شعارك في logo/logo.png
يحتاج PHP مع Imagick مثبتة  ( php-imagick )
مواقع الأخبار مثل صحيفة الرياض تستخدم روابط صور مؤقتة (Dynamic URLs)

او الرابط نفسه من صحيفة الرياض غير موجود أو انتهت صلاحيته.
[صورة مرفقة: 177461173141861.gif]
الرد }}}
تم الشكر بواسطة: nnnjk , nnnjk , nnnjk


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


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


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