تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
طلب اضافة ختم الصور لهذا الكود
#11
تجربة على الهامش  : 
هذا كود اخر  طالما عندك  PHP 5.6 
PHP كود :
<?php
/**
 * نظام تحميل ومعالجة الصور مع علامة مائية
 * الإصدار: 2.0
 */

// إعدادات عامة
set_time_limit(0);
ini_set('memory_limit''512M');
error_reporting(E_ALL);
ini_set('display_errors'0);
ini_set('log_errors'1);

// ============================================================
// الدوال الأساسية
// ============================================================

/**
 * تحميل الصورة من الرابط
 */
function download_image($url) {
    // فحص وجود cURL
    if (!function_exists('curl_init')) {
        // استخدام file_get_contents كبديل
        $context stream_context_create([
            'http' => [
                'timeout' => 60,
                'user_agent' => 'Mozilla/5.0'
            ],
            'ssl' => [
                'verify_peer' => false,
                'verify_peer_name' => false
            
]
        ]);
        
        $data 
= @file_get_contents($urlfalse$context);
        if ($data === false) {
            return false;
        }
        
        
// فحص نوع المحتوى
        $content_type = @get_headers($url1)['Content-Type'] ?? '';
        if (strpos($content_type'image') === false && strlen($data) < 100) {
            return false;
        }
        
        
return $data;
    }
    
    
// استخدام cURL
    $ch curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_TIMEOUT => 60,
        CURLOPT_CONNECTTIMEOUT => 30,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_SSL_VERIFYHOST => false,
        CURLOPT_ENCODING => '',
        CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
    ]);
    
    $data 
curl_exec($ch);
    $http_code curl_getinfo($chCURLINFO_HTTP_CODE);
    $curl_error curl_error($ch);
    curl_close($ch);
    
    
if ($http_code != 200 || empty($data)) {
        error_log("Download failed: HTTP $http_code, Error: $curl_error, URL: $url");
        return false;
    }
    
    
return $data;
}

/**
 * الحصول على امتداد الصورة
 */
function get_image_extension($url$data) {
    // 1. محاولة من الرابط
    $path parse_url($urlPHP_URL_PATH);
    $ext strtolower(pathinfo($pathPATHINFO_EXTENSION));
    
    
// 2. فحص نوع الملف من البيانات
    if (empty($ext) || !in_array($ext, ['jpg''jpeg''png''gif''webp'])) {
        $finfo finfo_open(FILEINFO_MIME_TYPE);
        $mime_type finfo_buffer($finfo$data);
        finfo_close($finfo);
        
        
switch ($mime_type) {
            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:
                $ext 'jpg';
        }
    }
    
    
// تأكد من أن الامتداد مدعوم
    $supported = ['jpg''jpeg''png''gif''webp'];
    if (!in_array($ext$supported)) {
        $ext 'jpg';
    }
    
    
return $ext;
}

/**
 * إضافة علامة مائية للصورة
 */
function add_watermark($image_path$ext$logo_path) {
    // فحص وجود الصورة والعلامة
    if (!file_exists($image_path) || !file_exists($logo_path)) {
        error_log("File not found: Image=" $image_path ", Logo=" $logo_path);
        return false;
    }
    
    
// فحص دعم GD
    if (!extension_loaded('gd')) {
        error_log("GD extension not loaded");
        return false;
    }
    
    $ext 
strtolower($ext);
    
    
// تحميل الصورة الأصلية
    $image null;
    switch ($ext) {
        case 'jpg':
        case 'jpeg':
            $image = @imagecreatefromjpeg($image_path);
            break;
        case 'png':
            $image = @imagecreatefrompng($image_path);
            break;
        case 'gif':
            $image = @imagecreatefromgif($image_path);
            break;
        case 'webp':
            if (function_exists('imagecreatefromwebp')) {
                $image = @imagecreatefromwebp($image_path);
            }
            break;
    }
    
    
if (!$image) {
        error_log("Failed to load image: $image_path");
        return false;
    }
    
    
// تحميل العلامة المائية
    $logo = @imagecreatefrompng($logo_path);
    if (!$logo) {
        error_log("Failed to load logo: $logo_path");
        imagedestroy($image);
        return false;
    }
    
    
// حساب الأبعاد
    $img_w imagesx($image);
    $img_h imagesy($image);
    $logo_w imagesx($logo);
    $logo_h imagesy($logo);
    
    
// إذا كانت الصورة أصغر من العلامة، لا نضيف علامة
    if ($img_w <= $logo_w 10 || $img_h <= $logo_h 10) {
        imagedestroy($image);
        imagedestroy($logo);
        return true;
    }
    
    
// وضع العلامة في الزاوية السفلية اليمنى
    $pos_x $img_w $logo_w 10;
    $pos_y $img_h $logo_h 10;
    
    
// دمج الصور
    imagealphablending($imagetrue);
    imagecopy($image$logo$pos_x$pos_y00$logo_w$logo_h);
    
    
// حفظ الصورة
    $save_result false;
    switch ($ext) {
        case 'jpg':
        case 'jpeg':
            $save_result = @imagejpeg($image$image_path90);
            break;
        case 'png':
            $save_result = @imagepng($image$image_path9);
            break;
        case 'gif':
            $save_result = @imagegif($image$image_path);
            break;
        case 'webp':
            if (function_exists('imagewebp')) {
                $save_result = @imagewebp($image$image_path90);
            }
            break;
    }
    
    imagedestroy
($image);
    imagedestroy($logo);
    
    
return $save_result;
}

/**
 * المعالجة الرئيسية للصورة
 */
function process_image($url$save_path_without_ext$logo_path) {
    // 1. فحص المعلمات
    if (empty($url) || empty($save_path_without_ext)) {
        error_log("Invalid parameters");
        return ['success' => false'error' => 'Invalid parameters'];
    }
    
    
// 2. تحميل الصورة
    $image_data download_image($url);
    if (!$image_data) {
        return ['success' => false'error' => 'Failed to download image'];
    }
    
    
// 3. تحديد الامتداد
    $ext get_image_extension($url$image_data);
    
    
// 4. إنشاء المجلد إذا لم يكن موجوداً
    $dir dirname($save_path_without_ext);
    if (!is_dir($dir)) {
        if (!mkdir($dir0755true)) {
            return ['success' => false'error' => 'Failed to create directory: ' $dir];
        }
    }
    
    
// 5. حفظ الصورة مؤقتاً
    $temp_file $save_path_without_ext '_temp.' $ext;
    if (file_put_contents($temp_file$image_data) === false) {
        return ['success' => false'error' => 'Failed to save temporary file'];
    }
    
    
// 6. التحقق من صحة الصورة
    $image_info = @getimagesize($temp_file);
    if (!$image_info) {
        @unlink($temp_file);
        return ['success' => false'error' => 'Invalid image file'];
    }
    
    
// 7. إعادة تسمية الملف
    $final_file $save_path_without_ext '.' $ext;
    if (!rename($temp_file$final_file)) {
        @unlink($temp_file);
        return ['success' => false'error' => 'Failed to rename file'];
    }
    
    
// 8. إضافة العلامة المائية (اختيارية)
    if (!empty($logo_path) && file_exists($logo_path)) {
        $watermark_result add_watermark($final_file$ext$logo_path);
        if (!$watermark_result) {
            error_log("Warning: Failed to add watermark to $final_file");
        }
    }
    
    
// 9. إرجاع النتيجة
    return [
        'success' => true,
        'file' => $final_file,
        'url' => $url,
        'extension' => $ext,
        'size' => filesize($final_file)
    ];
}

/**
 * دالة مبسطة للاستخدام السريع
 */
function download_and_watermark($url$save_path$logo_path null) {
    $result process_image($url$save_path$logo_path);
    
    
if ($result['success']) {
        return $result['file'];
    } else {
        error_log("Process failed: " $result['error']);
        return false;
    }
}

// ============================================================
// مثال على الاستخدام
// ============================================================

// إذا تم استدعاء الملف مباشرة (وليس ضمن ملف آخر)
if (basename($_SERVER['PHP_SELF']) == basename(__FILE__)) {
    
    
// إعدادات
    $url "https://example.com/image.webp";
    $save "uploads/2026/04/img_1";
    $logo "uploads/logo.png";
    
    
// فحص وجود مجلد uploads
    if (!is_dir('uploads')) {
        mkdir('uploads'0755);
        echo "Created uploads directory\n";
    }
    
    
// فحص وجود ملف الشعار
    if (!file_exists($logo)) {
        echo "Warning: Logo file not found at: $logo\n";
        echo "Image will be downloaded without watermark\n\n";
        $logo null;
    }
    
    
// تنفيذ العملية
    echo "Processing image...\n";
    $result process_image($url$save$logo);
    
    
if ($result['success']) {
        echo "Successfully saved:\n";
        echo "File: " $result['file'] . "\n";
        echo "Size: " round($result['size'] / 10242) . " KB\n";
        echo "Extension: " $result['extension'] . "\n";
        echo "Original URL: " htmlspecialchars($result['url']) . "\n";
        
        
// عرض الصورة
        if (file_exists($result['file'])) {
            echo "\n<img src='" $result['file'] . "' style='max-width:300px; border:1px solid #ddd; padding:5px;'>\n";
        }
    } else {
        echo "Failed: " $result['error'] . "\n";
    }
}
?>
ملف فحص و تشخيص (diagnostic.php)
PHP كود :
<?php
echo "<h2>Server Environment Check</h2>";

// 1. PHP Information
echo "<h3>1. PHP Information</h3>";
echo 
"PHP Version: " phpversion() . "<br>";
echo 
"Memory Limit: " ini_get('memory_limit') . "<br>";
echo 
"Max Execution Time: " ini_get('max_execution_time') . "<br>";

// 2. Required Extensions
echo "<h3>2. Required Extensions</h3>";
$extensions = ['curl''gd''fileinfo'];
foreach (
$extensions as $ext) {
    $loaded extension_loaded($ext);
    echo $ext ": " . ($loaded "Installed" "Not Installed") . "<br>";
}

// 3. GD Format Support
if (extension_loaded('gd')) {
    echo "<h3>3. GD Format Support</h3>";
    $gd_info gd_info();
    echo "JPEG: " . ($gd_info['JPEG Support'] ? "Yes" "No") . "<br>";
    echo "PNG: " . ($gd_info['PNG Support'] ? "Yes" "No") . "<br>";
    echo "GIF: " . ($gd_info['GIF Read Support'] ? "Yes" "No") . "<br>";
    echo "WebP: " . (function_exists('imagewebp') ? "Yes" "No") . "<br>";
}

// 4. Folder Permissions
echo "<h3>4. Folder Permissions</h3>";
$folders = ['uploads'dirname(__FILE__)];
foreach (
$folders as $folder) {
    if (file_exists($folder)) {
        echo $folder ": Writable " . (is_writable($folder) ? "Yes" "No") . "<br>";
    } else {
        echo $folder ": Not found (will be created automatically)<br>";
    }
}

// 5. Test Image Download
echo "<h3>5. Test Image Download</h3>";
$test_url "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png";
$ch curl_init($test_url);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_TIMEOUT10);
$data curl_exec($ch);
$http curl_getinfo($chCURLINFO_HTTP_CODE);
curl_close($ch);

if (
$http == 200 && $data) {
    echo "Successfully downloaded test image (HTTP $http)<br>";
    
    
// Save test image
    $test_file 'uploads/test_image.png';
    if (file_put_contents($test_file$data)) {
        echo "Successfully saved test image: $test_file<br>";
        echo "<img src='$test_file' style='max-width:200px;'>";
    }
} else {
    echo "Failed to download test image (HTTP $http)<br>";
}

echo 
"<h3>Check Complete</h3>";
echo 
"<p>If all items show 'Yes' or 'Installed', the system is working correctly.</p>";
?>
طريقة الاستخدام : 
PHP كود :
<?php
// استدعاء ملف النظام
require_once 'image_processor.php';

// استخدام الدالة المبسطة
$result download_and_watermark(
    'https://example.com/image.jpg',
    'uploads/2026/04/my_image',
    'uploads/logo.png'
);

if (
$result) {
    echo "Image saved at: " $result;
} else {
    echo "Failed to download image";
}

// استخدام الدالة المتقدمة
$details process_image(
    'https://example.com/image.webp',
    'uploads/2026/04/my_image',
    'uploads/logo.png'
);

if (
$details['success']) {
    echo "Saved: " $details['file'];
    echo "Size: " round($details['size'] / 10242) . " KB";
} else {
    echo "Error: " $details['error'];
}
?>

لا تنسى الاستغفار
[صورة مرفقة: 177461173141861.gif]
الرد }}}
تم الشكر بواسطة: nnnjk , nnnjk , nnnjk
#12
يعطيك العافيه اخوي
تعطل الكرون ولم ينقل الصور
هذا كود بسيط مباشر لنقل الصور بدون مهام مجدوله
<?php
PHP كود :
******************************************************************************
Image cache plugin extension                                                 *
* (
CCopyright Y2K Software s.a.s., Italy 2006 All Rights Reserved          *
* ---------------------------------------------------------------------------- *
Saves images between the [IMG] and [/IMGtags to file system                *
Requires a full access folder at <forumhome>/imgcache2/                       *
*******************************************************************************/
$context stream_context_create([
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
    ],
]);
// Get cache ID (collision-free) -----------------------------------------------
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)
{
    // Occurrance check --------------------------------------------------------
    $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;
        }
    
        
// Adjust pointers
        $pos_start += 5;
        $pos_end--;
    
        
// Add reference to array if valid comparison
        $files[$n]['url'] = substr($message_body$pos_start$pos_end $pos_start 1);
        $n++;
    }

    // If there was no occurrance, exit from function --------------------------
    if(!$n)
    {
        return $old_message;
    }

    // Don't change already cached files ---------------------------------------
    for($i 0$i $n$i++)
    {
        if(strpos($files[$i]['url'], $forum_home 'imgcache/2/') !== FALSE)
        {
            $files[$i]['url'] = '';
        }
            $matar=$files[$i]['url'];
            $matar=strtolower($matar);
            if (eregi("alshafeen.site"$matar) or eregi("alsh3er.com"$matar))  $files[$i]['url'] = '';


    }

    // Discard duplicates ------------------------------------------------------
    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'] = '';
                }
            }
        }
    }

    // Get contents ------------------------------------------------------------
    for($i 0$i $n$i++)
    {
        // Get content if url is valid
        if(@getimagesize($files[$i]['url']))
        {
            // A localhost file will fail, also not existing references
            $files[$i]['content'] = @file_get_contents($files[$i]['url'],false,$context);
            $typemkhm=strrchr($files[$i]['url'],'.');
        }
    }

    // Save file contents to file system ---------------------------------------
    for($i 0$i $n$i++)
    {
        // Write if contents are available
        $k strlen($files[$i]['content']);
        if($k)
        {
            // Get unique cache ID (collision-free)
            $id GetCacheID();
            // Create filename
            $f 'imgcache/2/' sprintf('%d'$id) . 'alsh3er'.$typemkhm;
            // Open file
            $hFile = @fopen($f'wb');
            if($hFile)
            {
                // Write file contents
                $m 0;
                $m = @fwrite($hFile$files[$i]['content'], $k);
                // Close file
                fclose($hFile);
                // Free some memory
                $files[$i]['content'] = '';
                // Replace URL's if successfully written
                if($m == $k)
                {
                    $old_url $files[$i]['url'];
                    $new_url $forum_home $f;
                    $old_message str_replace($old_url$new_url$old_message);
                }
            }
        }
    }

    return $old_message;
}
?>
فليت تعدل عليه ختم الصور
الرد }}}
تم الشكر بواسطة: Amir_Alzubidy
#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
#14
مشكور
لم يختم الصوره
وكان رابط الصوره بعد النقل ناقص نوع الملف
مثلا
http://domain.site/vb/imgcache/2/10alsh3er.

بعد تحرير الملف ووضع كلاس ختم الصور اعلى الملف نقل و ختم الصوره لاكن الرابط ناقص بدون نوع الملف
واذا كان رابط الملف يحتوي ssl لا ينقل الصوره

يعطيك العافيه
اذا كان رابط الصوره ليس فيها نوع الملف فاانه ينقل الصوره بدون نوع امتداد الملف واذا كان الرابط يحتوي على نوع الملف في اخر الرابط فاانه ينقل الصوره مع نوع الملف
ملاحظه عند كتابة الشعار بالعربي
يختم النص معكوس ومتقطع
الرد }}}
تم الشكر بواسطة:
#15
تعديل المشاركة رقم 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)";
    $result $db->query_write($SQL);
    if(!$result) return null;
    return $db->insert_id();
}

function 
AddWatermark($filepath$extension)
{
    $ext strtolower(ltrim($extension'.'));

    switch($ext) {
        case 'jpg':
        case 'jpeg':
            $image = @imagecreatefromjpeg($filepath);
            break;
        case 'png':
            $image = @imagecreatefrompng($filepath);
            break;
        case 'gif':
            $image = @imagecreatefromgif($filepath);
            break;
        default:
            return;
    }

    if(!$image) return;

    $img_w imagesx($image);
    $img_h imagesy($image);

    $watermark_text 'alsh3er.com';
    $font           5;
    $text_w         imagefontwidth($font) * strlen($watermark_text);
    $text_h         imagefontheight($font);
    $margin         10;

    $color imagecolorallocatealpha($image25525525560);

    imagestring(
        $image,
        $font,
        $img_w $text_w $margin,
        $img_h $text_h $margin,
        $watermark_text,
        $color
    
);

    switch($ext) {
        case 'jpg':
        case 'jpeg':
            imagejpeg($image$filepath90);
            break;
        case 'png':
            imagepng($image$filepath);
            break;
        case 'gif':
            imagegif($image$filepath);
            break;
    }

    imagedestroy($image);
}

function 
CacheImages($message_body$old_message$forum_home)
{
    global $context;

    // التحقق من وجود المجلد وإنشاؤه إذا غير موجود
    if(!is_dir('imgcache/2/'))
    {
        mkdir('imgcache/2/'0755true);
    }

    // التحقق من صلاحيات الكتابة
    if(!is_writable('imgcache/2/'))
    {
        error_log('imgcache/2/ غير قابل للكتابة');
        return $old_message;
    }

    $n       0;
    $pos_end = -1;

    for(;;)
    {
        $pos_start strpos(strtolower($message_body), ''$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(strpos($matar'alshafeen.site') !== false || strpos($matar'alsh3er.com') !== false)
            $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'] = '';
            }
        }
    }

    // تحميل الصور مع SSL context
    for($i 0$i $n$i++)
    {
        if(empty($files[$i]['url'])) continue;

        // getimagesize مع context لدعم HTTPS
        if(@getimagesize($files[$i]['url'], $info$context))
        {
            $files[$i]['content'] = @file_get_contents($files[$i]['url'], false$context);
            $files[$i]['ext']     strrchr($files[$i]['url'], '.');

            if(empty($files[$i]['content']))
            {
                error_log('فشل تحميل الصورة: ' $files[$i]['url']);
            }
        }
    }

    // حفظ الصور وإضافة الختم
    for($i 0$i $n$i++)
    {
        $k strlen($files[$i]['content']);
        if(!$k) continue;

        // التحقق من ID قاعدة البيانات
        $id GetCacheID();
        if(!$id) continue;

        $ext   $files[$i]['ext'];
        $f     'imgcache/2/' sprintf('%d'$id) . 'alsh3er' $ext;
        $hFile = @fopen($f'wb');

        if($hFile)
        {
            $m = @fwrite($hFile$files[$i]['content'], $k);
            fclose($hFile);
            $files[$i]['content'] = '';

            if($m == $k)
            {
                // إضافة الختم
                AddWatermark($f$ext);

                $old_url     $files[$i]['url'];
                $new_url     $forum_home $f;
                $old_message str_replace($old_url$new_url$old_message);
            }
            else
            {
                // حذف الملف لو الكتابة فشلت
                @unlink($f);
                error_log('فشلت الكتابة للملف: ' $f);
            }
        }
    }

    return $old_message;
}
?>
----------------------
حل بديل 
PHP كود :
<?php
/******************************************************************************
* Image Cache Plugin with Arabic Watermark - الكامل الجاهز                    *
* (C) Copyright Y2K Software s.a.s., Italy 2006 - Modified 2024               *
* ---------------------------------------------------------------------------- *
* ينقل الصور ويضيف ختم مائي عربي تلقائياً                                    *
*******************************************************************************/

$context stream_context_create([
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
    ],
]);

// =====================================================
// دالة الختم المائي العربي المتقدمة
// =====================================================
function addArabicWatermark($sourceImage$outputPath) {
    $imageInfo getimagesize($sourceImage);
    if (!$imageInfo) return false;
    
    $mime 
$imageInfo['mime'];
    
    
// تحميل الصورة حسب نوعها
    switch($mime) {
        case 'image/jpeg':
            $image imagecreatefromjpeg($sourceImage);
            break;
        case 'image/png':
            $image imagecreatefrompng($sourceImage);
            break;
        case 'image/gif':
            $image imagecreatefromgif($sourceImage);
            break;
        default:
            return false;
    }
    
    $width 
imagesx($image);
    $height imagesy($image);
    
    
// إنشاء ألوان الختم
    $white imagecolorallocatealpha($image2552552550);
    $black_shadow imagecolorallocatealpha($image00030);
    
    
// نصوص الختم (يمكنك تغييرها)
    $mainText "القناة الشعرية";
    $subText "www.alsh3er.com";
    
    $fontSizeMain 
min(36$height 0.08);  // حجم ديناميكي
    $fontSizeSub min(20$height 0.04);
    
    $fontPath 
__DIR__ '/fonts/Amiri-Regular.ttf';
    
    
if (!file_exists($fontPath)) {
        // خط احتياطي إذا لم يوجد الخط
        $mainText "ALSH3ER.COM";
        $subText "Watermark";
    }
    
    
// حساب أبعاد النصوص
    $bboxMain imagettfbbox($fontSizeMain0$fontPath$mainText);
    $bboxSub imagettfbbox($fontSizeSub0$fontPath$subText);
    
    $textWidthMain 
$bboxMain[4] - $bboxMain[6];
    $textHeightMain $bboxMain[5] - $bboxMain[1];
    $textWidthSub $bboxSub[4] - $bboxSub[6];
    $textHeightSub $bboxSub[5] - $bboxSub[1];
    
    
// موضع النص في المنتصف مع مسافة
    $xMain = ($width $textWidthMain) / 2;
    $yMain = ($height $textHeightMain) / 2;
    $xSub = ($width $textWidthSub) / 2;
    $ySub $yMain $textHeightSub 10;
    
    
// الظل الأسود
    imagettftext($image$fontSizeMain0$xMain+2$yMain+2$black_shadow$fontPath$mainText);
    imagettftext($image$fontSizeSub0$xSub+1$ySub+1$black_shadow$fontPath$subText);
    
    
// النص الأبيض الرئيسي
    imagettftext($image$fontSizeMain0$xMain$yMain$white$fontPath$mainText);
    imagettftext($image$fontSizeSub0$xSub$ySub$white$fontPath$subText);
    
    
// حفظ الصورة
    $result false;
    switch($mime) {
        case 'image/jpeg':
            $result imagejpeg($image$outputPath92);
            break;
        case 'image/png':
            $result imagepng($image$outputPath8);
            break;
        case 'image/gif':
            $result imagegif($image$outputPath);
            break;
    }
    
    imagedestroy
($image);
    return $result;
}

// =====================================================
// الحصول على ID فريد للصورة
// =====================================================
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)
{
    // البحث عن جميع العلامات [img]...[/img]
    $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'] = '';
            continue;
        }
        
        $matar 
strtolower($files[$i]['url']);
        if (stripos($matar"alshafeen.site") !== false || stripos($matar"alsh3er.com") !== false) {
            $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$context);
        }
    }

    // حفظ الصور مع الختم المائي
    for($i 0$i $n$i++)
    {
        $k strlen($files[$i]['content']);
        if($k)
        {
            $id GetCacheID();
            $tempFile 'imgcache/2/temp_' $id '.tmp';
            $finalFile 'imgcache/2/' $id '_watermarked.jpg';
            
            
// حفظ الملف المؤقت
            $hTempFile = @fopen($tempFile'wb');
            if($hTempFile)
            {
                $m = @fwrite($hTempFile$files[$i]['content'], $k);
                fclose($hTempFile);
                
                
if($m == $k)
                {
                    // إضافة الختم واستبدال الرابط
                    if(addArabicWatermark($tempFile$forum_home $finalFile))
                    {
                        @unlink($tempFile);  // حذف المؤقت
                        $old_url $files[$i]['url'];
                        $new_url $forum_home $finalFile;
                        $old_message str_replace($old_url$new_url$old_message);
                    }
                }
            }
        }
    }

    return $old_message;
}

// نهاية الكود =====================================================
?>
[صورة مرفقة: 177461173141861.gif]
الرد }}}
تم الشكر بواسطة: nnnjk , nnnjk
#16
يعطيك العافيه
بالنسبه للكود الاول في مشاركتك الاخيره ظهر لي خطأ طويل جدا متكرر كما في الصوره
وبالتسبه للكود الثاني لم ينقل الصور


الملفات المرفقة الشكل المصغر
   
الرد }}}
تم الشكر بواسطة: Amir_Alzubidy
#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
#18
وضعت كودك الاخير
فلم ينقل الصور من موقع صحيفة الرياض
الجمعة 16 شوال 1447 01:22:50 مساءً
[صورة مرفقة: 4360079361.jpg]
الرد }}}
تم الشكر بواسطة: Amir_Alzubidy
#19
الحين الكود شغال يعني المشكلة فقط بالصورة ؟

موقع صحيفة الرياض تحديداً يمنع التحميل العادي حتى مع Mozilla/5.0
لأنه يحتاج Headers إضافية (خصوصاً Referer + Accept).

نجرب تبديل او تعديل دالة التحميل :
PHP كود :
function DownloadImage($url) {
    if (empty($url)) return false;

    $ch curl_init($url);

    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_SSL_VERIFYHOST => false,
        CURLOPT_TIMEOUT => 20,

        CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/120 Safari/537.36',

        CURLOPT_HTTPHEADER => [
            'Accept: image/webp,image/apng,image/*,*/*;q=0.8',
            'Accept-Language: ar,en;q=0.9',
            'Connection: keep-alive',
            'Referer: https://www.alriyadh.com/'
        ]
    ]);

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

    return $data;

[صورة مرفقة: 177461173141861.gif]
الرد }}}
تم الشكر بواسطة: nnnjk
#20
بعد تطبيق الكود الاخير ظهر خطأ
Parse error: syntax error, unexpected ';' in /home/username/domains/alshafeen.site/public_html/vb/y2kswimgcache.php on line 78
مركب سكربت بسيط لرفع الملفات
ينقل الصور جميعها حتى من صحيفة الرياض
جرب
http://alshafeen.site/uploads.php

بعد تطبيق الكود الاخير ظهر خطأ
Parse error: syntax error, unexpected ';' in /home/username/domains/alshafeen.site/public_html/vb/y2kswimgcache.php on line 78
مركب سكربت بسيط لرفع الملفات
ينقل الصور جميعها حتى من صحيفة الرياض
جرب
http://alshafeen.site/uploads.php
مركب فيه هذا الكود فقط
PHP كود :
$context stream_context_create([
    
'ssl' => [
        
'verify_peer' => false,
        
'verify_peer_name' => false,
    ],
]); 
الرد }}}
تم الشكر بواسطة:



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


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