تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
طلب اضافة ختم الصور لهذا الكود
#13
PHP كود :
<?php
$context 
stream_context_create([
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
    ],
]);

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

function 
CacheImages($message_body$old_message$forum_home)
{
    $n 0;
    $pos_end = -1;
    for(;;)
    {
        $pos_start strpos(strtolower($message_body), '[img]'$pos_end 1);
        if($pos_start === FALSE) break;

        $pos_end strpos(strtolower($message_body), '[/img]'$pos_start 1);
        if($pos_end === FALSE) break;

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

    if(!$n) return $old_message;

    for($i 0$i $n$i++)
    {
        if(strpos($files[$i]['url'], $forum_home 'imgcache/2/') !== FALSE)
            $files[$i]['url'] = '';
        
        $matar 
strtolower($files[$i]['url']);
        if (preg_match("/alshafeen.site|alsh3er.com/i"$matar)) $files[$i]['url'] = '';
    }

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

    for($i 0$i $n$i++)
    {
        if(@getimagesize($files[$i]['url']))
        {
            $files[$i]['content'] = @file_get_contents($files[$i]['url'], false$GLOBALS['context']);
            $typemkhm strrchr($files[$i]['url'], '.');
        }
    }

    for($i 0$i $n$i++)
    {
        $k strlen($files[$i]['content']);
        if($k)
        {
            $id GetCacheID();
            $f 'imgcache/2/' sprintf('%d'$id) . 'alsh3er' $typemkhm;
            $hFile = @fopen($f'wb');
            if($hFile)
            {
                @fwrite($hFile$files[$i]['content'], $k);
                fclose($hFile);
                $files[$i]['content'] = '';

                // إضافة ختم نصي على الصورة
                AddWatermark($f"alsh3er.site");

                $old_url $files[$i]['url'];
                $new_url $forum_home $f;
                $old_message str_replace($old_url$new_url$old_message);
            }
        }
    }

    return $old_message;
}

function 
AddWatermark($imagePath$text)
{
    $info getimagesize($imagePath);
    $mime $info['mime'];

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

    $color imagecolorallocatealpha($img25525525550); // أبيض شفاف
    $font __DIR__ '/arial.ttf'// ضع خط TTF هنا
    $font_size 12;

    if(file_exists($font)) {
        $bbox imagettfbbox($font_size0$font$text);
        $x imagesx($img) - ($bbox[2] - $bbox[0]) - 10;
        $y imagesy($img) - 10;
        imagettftext($img$font_size0$x$y$color$font$text);
    }

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

    imagedestroy($img);
}
?>
الكود الحالي لا يدعم WebP، فقط jpg/png/gif.
إذا فيه صور WebP، ما رح ينقلها أو يضيف لها ختم
إذا الصورة.jpg,.png, أو.gifالكود يشتغل تمام
إذا الصورة.imagecreatefromjpeg/png/gif
تفشل، وما رح ينزل الصورة ولا يضيف الختم
الحل هو استخدام دوال WebP

-----------------------

كود  اخر باستخدام  دوال WebP : 

يدعم جميع أنواع الصور مثل JPG, PNG, GIF, WebP.
اضافة ختم نصي أسفل يمين كل صورة.
يعمل مباشرة بدون كرون 
تنقل الصور من أي URL حتى لو SSL غير موثوق.

PHP كود :
<?php
$context 
stream_context_create([
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
    ],
]);
function 
GetCacheID()
{
    global $db;
    $SQL "INSERT INTO " TABLE_PREFIX "y2ksw_imgcache2 (ID) VALUES (0)";
    $db->query_write($SQL);
    return $db->insert_id();
}
function 
CacheImages($message_body$old_message$forum_home)
{
    $n 0;
    $pos_end = -1;
    for(;;)
    {
        $pos_start strpos(strtolower($message_body), '[img]'$pos_end 1);
        if($pos_start === FALSE) break;
        $pos_end strpos(strtolower($message_body), '[/img]'$pos_start 1);
        if($pos_end === FALSE) break;
        $pos_start += 5;
        $pos_end--;
        $files[$n]['url'] = substr($message_body$pos_start$pos_end $pos_start 1);
        $n++;
    }
    if(!$n) return $old_message;
    for($i 0$i $n$i++)
    {
        if(strpos($files[$i]['url'], $forum_home 'imgcache/2/') !== FALSE)
            $files[$i]['url'] = '';
        
        $matar 
strtolower($files[$i]['url']);
        if (preg_match("/alshafeen.site|alsh3er.com/i"$matar)) $files[$i]['url'] = '';
    }
    for($i 0$i $n$i++)
    {
        $a $files[$i]['url'];
        if($a)
        {
            for($j $i 1$j $n$j++)
            {
                if($files[$j]['url'] == $a$files[$j]['url'] = '';
            }
        }
    }
    for($i 0$i $n$i++)
    {
        if(@getimagesize($files[$i]['url']))
        {
            $files[$i]['content'] = @file_get_contents($files[$i]['url'], false$GLOBALS['context']);
            $files[$i]['ext'] = strtolower(pathinfo($files[$i]['url'], PATHINFO_EXTENSION));
        }
    }
    for($i 0$i $n$i++)
    {
        $k strlen($files[$i]['content']);
        if($k)
        {
            $id GetCacheID();
            $f 'imgcache/2/' sprintf('%d'$id) . 'alsh3er.' $files[$i]['ext'];
            $hFile = @fopen($f'wb');
            if($hFile)
            {
                @fwrite($hFile$files[$i]['content'], $k);
                fclose($hFile);
                $files[$i]['content'] = '';
                // إضافة ختم نصي على الصورة
                AddWatermark($f"alsh3er.site");
                $old_url $files[$i]['url'];
                $new_url $forum_home $f;
                $old_message str_replace($old_url$new_url$old_message);
            }
        }
    }
    return $old_message;
}
function 
AddWatermark($imagePath$text)
{
    $info getimagesize($imagePath);
    $mime $info['mime'];
    switch($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); // أبيض شفاف
    $font __DIR__ '/arial.ttf'// ضع خط TTF هنا
    $font_size 12;
    if(file_exists($font)) {
        $bbox imagettfbbox($font_size0$font$text);
        $x imagesx($img) - ($bbox[2] - $bbox[0]) - 10;
        $y imagesy($img) - 10;
        imagettftext($img$font_size0$x$y$color$font$text);
    }
    switch($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 - 02-04-26, 02:02 AM


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


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