تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
طلب اضافة ختم الصور لهذا الكود
#17
تعديل الكود الاول في المشاركة رقم 15#
و تاكد من المجلد  imgcache/2/ 
لازم يكون chmod 777

PHP كود :
<?php

function GetCacheID() {
    global $db;
    $SQL "INSERT INTO " TABLE_PREFIX "y2ksw_imgcache2 (ID) VALUES (0)";
    $db->query_write($SQL);
    return $db->insert_id();
}

function 
DownloadImage($url) {
    if (empty($url)) return false;

    $ch curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_SSL_VERIFYHOST => false,
        CURLOPT_TIMEOUT => 20,
        CURLOPT_USERAGENT => 'Mozilla/5.0'
    ]);

    $data curl_exec($ch);
    curl_close($ch);

    return $data;
}

function 
CacheImages($message_body$old_message$forum_home) {

    $files = [];
    $n 0;
    $pos_end = -1;

    while (($pos_start strpos(strtolower($message_body), ''$pos_start 1);
        if ($pos_end === false) break;

        $pos_start += 5;
        $pos_end--;

        $url trim(substr($message_body$pos_start$pos_end $pos_start 1));
        $files[$n]['url'] = $url;
        $n++;
    }

    if (!$n) return $old_message;

    foreach ($files as $i => $file) {

        if (empty($file['url'])) continue;

        if (!empty($forum_home) && strpos($file['url'], $forum_home 'imgcache/2/') !== false) {
            $files[$i]['url'] = '';
            continue;
        }

        $matar strtolower($file['url']);
        if (preg_match("/alshafeen.site|alsh3er.com/i"$matar)) {
            $files[$i]['url'] = '';
            continue;
        }
    }

    for ($i 0$i $n$i++) {
        if (empty($files[$i]['url'])) continue;

        for ($j $i 1$j $n$j++) {
            if ($files[$j]['url'] == $files[$i]['url']) {
                $files[$j]['url'] = '';
            }
        }
    }

    foreach ($files as $file) {

        if (empty($file['url'])) continue;

        $content DownloadImage($file['url']);
        if (!$content) continue;

        $tmp tempnam(sys_get_temp_dir(), "img_");
        file_put_contents($tmp$content);

        $info = @getimagesize($tmp);
        if (!$info) {
            unlink($tmp);
            continue;
        }

        switch ($info['mime']) {
            case 'image/jpeg'$ext 'jpg'; break;
            case 'image/png':  $ext 'png'; break;
            case 'image/gif':  $ext 'gif'; break;
            case 'image/webp'$ext 'webp'; break;
            default:
                unlink($tmp);
                continue 2;
        }

        $id GetCacheID();
        $new_file 'imgcache/2/' $id 'alsh3er.' $ext;

        copy($tmp$new_file);
        unlink($tmp);

        AddWatermark($new_file"alsh3er.site");

        $old_message str_replace($file['url'], $forum_home $new_file$old_message);
    }

    return $old_message;
}

function 
AddWatermark($imagePath$text) {

    $info getimagesize($imagePath);
    if (!$info) return;

    switch ($info['mime']) {
        case 'image/jpeg'$img imagecreatefromjpeg($imagePath); break;
        case 'image/png':  $img imagecreatefrompng($imagePath); break;
        case 'image/gif':  $img imagecreatefromgif($imagePath); break;
        case 'image/webp'$img imagecreatefromwebp($imagePath); break;
        default: return;
    }

    $color imagecolorallocatealpha($img25525525550);

    imagestring(
        $img,
        3,
        imagesx($img) - 120,
        imagesy($img) - 15,
        $text,
        $color
    
);

    switch ($info['mime']) {
        case 'image/jpeg'imagejpeg($img$imagePath); break;
        case 'image/png':  imagepng($img$imagePath); break;
        case 'image/gif':  imagegif($img$imagePath); break;
        case 'image/webp'imagewebp($img$imagePath); break;
    }

    imagedestroy($img);
}

?>
[صورة مرفقة: 177461173141861.gif]
الرد }}}
تم الشكر بواسطة: nnnjk , nnnjk


الردود في هذا الموضوع
RE: طلب اضافة ختم الصور لهذا الكود - بواسطة Amir_Alzubidy - 03-04-26, 12:18 AM


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


يقوم بقرائة الموضوع: