منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : طلب اضافة ختم الصور لهذا الكود
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
الصفحات : 1 2 3 4 5
السلام عليكم
حاولت مرات عديده ان اختم صور كاش الصور بصورة logi.png
فلم افلح فليت احد الاخوان يساعدني
هذا الكود 
PHP كود :
<?php
 
function watermark($filename$extension$logo){

    if (
preg_match("/jpg|jpeg/",$extension)){$src_img=imagecreatefromjpeg($filename);}

    if (
preg_match("/webp/",$extension)){$src_img=imagecreatefromwebp($filename);}
    if (
preg_match("/png/",$extension)){$src_img=imagecreatefrompng($filename);}
    if (
preg_match("/gif/",$extension)){$src_img=imagecreatefromgif($filename);}

    
$src_logo imagecreatefrompng($logo);

    $bwidth  imageSX($src_img);
    $bheight imageSY($src_img);
    $lwidth  imageSX($src_logo);
    $lheight imageSY($src_logo);

    
//fix bug for 1beta3
    
if ( $bwidth 160 &&  $bheight 130 ) {

    $src_x $bwidth - ($lwidth 5);
    $src_y $bheight - ($lheight 5);
    ImageAlphaBlending($src_imgtrue);
    ImageCopy($src_img,$src_logo,$src_x,$src_y,0,0,$lwidth,$lheight);

    if (
preg_match("/jpg|jpeg/",$extension)){imagejpeg($src_img$filename);}
    if (
preg_match("/png/",$extension)){imagepng($src_img$filename);}
if (
preg_match("/webp/",$extension)){imagewebp($src_img$filename);}
    if (
preg_match("/gif/",$extension)){imagegif($src_img$filename);}

    }
# < 150
    
else
    {
    return 
false;
    }

}

/*============================================================================*\
|| ########################################################################## ||
|| # Import External Images                                                 # ||
|| # ---------------------------------------------------------------------- # ||
|| # (C) Copyright Y2K Software s.a.s. 2010 - All Rights Reserved.          # ||
|| # This file may not be redistributed in whole or significant part.       # ||
|| ########################################################################## ||
\*============================================================================*/

/**
 * @author Y2K Software
 * @copyright (C) Copyright Y2K Software 2010 - All Rights Reserved
 * @version 1.0.2
 * @link www.pagerobot.com
 */

error_reporting(E_ALL & ~ E_NOTICE);
if(!
is_object($vbulletin->db))
{
    exit;
}

if (!
$vbulletin->options['mwaextraadmin5_setting_active_imgcache'])
{
    exit;
}

/**
 * iei_cache_registered_images()
 * 
 * Reads all registered images into memory for fast parsing.
 * If you have a large board, you may need to clean out this table from time to time by removing old records.
 * 
 * @return array $images
 */
function iei_cache_registered_images()
{
    global $vbulletin;

    $images = array();
    $SQL "SELECT oldurl, newurl 
        FROM " 
TABLE_PREFIX "iei_img";
    $rss $vbulletin->db->query_read($SQL);
    while($rs $vbulletin->db->fetch_array($rss))
    {
        $images["$rs[oldurl]"] = $rs['newurl'];
    }
    $vbulletin->db->free_result($rss);

    return $images;
}

/**
 * iei_normalize_path()
 * 
 * Avoid strange path names.
 * 
 * @param mixed $path
 * @return mixed $path
 */
function iei_normalize_path($path)
{
    if(substr($path, -11) != '/')
    {
        $path .= '/';
    }
    $path str_replace('\\''/'$path);
    if(strpos($path':'))
    {
        $path str_replace('//''/'$path);
    }

    return $path;
}

/**
 * iei_get_file_index()
 * 
 * Search a new file name.
 * 
 * @param mixed $path
 * @param mixed $extension
 * @return mixed $filename
 */
function iei_get_file_index(&$path, &$extension)
{
    for($i 1;; $i++)
    {
        $filename "$path/$i.$extension";
        if(!file_exists($filename))
        {
            return $filename;
        }
    }
}

/**
 * iei_get_file_extension()
 * 
 * Sanitize extension.
 * 
 * @param mixed $value
 * @param mixed $convert
 * @param mixed $extension
 * @return void
 */
function iei_get_file_extension(&$value, &$convert, &$extension)
{
    if(ALWAYS_CONVERT_IMAGES)
    {
        $convert true;
        $extension 'jpg';
        return;
    }

    $convert false;
    $i strrpos($value'.');
    if($i === false)
    {
        $convert true;
        $extension 'jpg';
        return;
    }

    $extension substr($value$i 1);
    if(strpos($extension'/') !== false || strpos($extension'&') !== false)
    {
        $convert true;
        $extension 'jpg';
    }

    $extension strtolower($extension);
}

/**
 * iei_get_contents()
 * 
 * Get file from remote site.
 * 
 * @param mixed $url
 * @return $contents / false on error
 */
function iei_get_contents(&$url)
{
    $ch 0;
    if(USE_CURL)
    {
        $ch = @curl_init($url);
        curl_setopt($chCURLOPT_BINARYTRANSFER1);
        curl_setopt($chCURLOPT_RETURNTRANSFER1);
        curl_setopt($chCURLOPT_FAILONERROR1);
        curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        curl_setopt($chCURLOPT_CONNECTTIMEOUT10);
        curl_setopt($chCURLOPT_TIMEOUT120);
        curl_setopt($chCURLOPT_REFERERAEI_BBURL '/');
        curl_setopt($chCURLOPT_USERAGENTAEI_FORUMDOMAIN);
        $contents = @curl_exec($ch);
        @curl_close($ch);
    }
    if(!$ch)
    {
        // If CURL didn't work, try it differently
        $contents = @file_get_contents($imagename);
    }

    return $contents $contents false;
}

// Get iei options
define('USE_CURL'function_exists('curl_init'));
foreach(
$vbulletin->options as $key => $value)
{
    if(strpos($key'iei_') === false)
    {
        continue;
    }
    $$key $value;
}
define('ALWAYS_CONVERT_IMAGES'$iei_always_convert_images);

// Adjust options
$bburl0 $vbulletin->options['bburl'];
if(
$iei_bburl_replacement)
{
    $bburl $iei_bburl_replacement '/';
}
else
{
    $bburl $bburl0 '/';
}
$iei_imported_images_folder iei_normalize_path($iei_imported_images_folder);
$iei_ignore explode("\r\n"$iei_ignore);
$iei_ignore[] = $bburl;
$iei_ignore[] = $bburl0 '/';
$iei_ignore[] = $iei_imported_images_folder;
if(
$iei_remove_invalid_images)
{
    $iei_ignore[] = $iei_invalid_image_replacement;
}

// Exclude all new records which have no images at all
$SQL "UPDATE " TABLE_PREFIX "post 
    SET iei_parsed=1
    WHERE iei_parsed=0
        AND NOT pagetext LIKE '%[/IMG]%'"
;
$vbulletin->db->query_write($SQL);

$mwaimgcache_mwanotforumid "AND thread.forumid NOT IN (0)";
$iei_ignore_usersp "AND post.userid NOT IN (0)";

if (
$vbulletin->options['mwaimgcache_mwanotforumid'])
{
$mwaimgcache_mwanotforumid "AND thread.forumid NOT IN (" $vbulletin->options['mwaimgcache_mwanotforumid'] . ")";
}

if (
$vbulletin->options['iei_ignore_users'])
{
$iei_ignore_usersp "AND post.userid NOT IN (" $vbulletin->options['iei_ignore_users'] . ")";
}

// For each record with images ...
$cnt 0;
$SQL "SELECT post.postid, post.userid, post.dateline, post.pagetext , post.iei_parsed
    FROM " 
TABLE_PREFIX "post AS post
    LEFT JOIN " 
TABLE_PREFIX "thread AS thread ON(thread.threadid = post.threadid)
    WHERE post.iei_parsed=0
        
$mwaimgcache_mwanotforumid
        
$iei_ignore_usersp
        AND post.pagetext LIKE '%[/IMG]%'
    ORDER BY post.dateline DESC"
;

$rss $vbulletin->db->query_read($SQL);
while(
$rs $vbulletin->db->fetch_array($rss))
{
    $cnt++;
    if($cnt $iei_max_post_count)
    {
        break;
    }
    if($cnt == 1)
    {
        // Cache registered images
        $images iei_cache_registered_images();
    }

    $pagetext $rs['pagetext'];

    // Find all embedded images
    if(!preg_match_all('/\[img.*?\](.*?)\[\/img\]/is'$pagetext$matches))
    {
        $SQL "UPDATE " TABLE_PREFIX "post 
            SET iei_parsed=1
            WHERE postid=
$rs[postid]";
        $vbulletin->db->query_write($SQL);
        continue;
    }

    $changed false;
    foreach($matches[1] as $key => $value)
    {
        $error 0;

        // Search for images to be ignored
        $ignore false;
        foreach($iei_ignore as $ivalue)
        {
            if($value && $ivalue && strpos($value$ivalue) !== false)
            {
                $ignore true;
                break;
            }
        }
        if($ignore)
        {
            continue;
        }

        // If we haven't got the image yet, download
        $filename $images["$value"];
        $newimage = !$filename;
        while($newimage)
        {
            // Get file from remote site
            if(!$contents iei_get_contents($value))
            {
                // Missing contents
                $error 1;
                break;
            }

            // Get file extension
            iei_get_file_extension($value$convert$extension);
$fileplace="images/imgcache";
@
watermark($fileplace,$extension,'$iei_imported_images_folder/logo.png');
            // Make path
            $path $iei_imported_images_folder date('Y/m'$rs['dateline']);
            @mkdir($path0755true);

            // Get file index
            $filename iei_get_file_index($path$extension);

            // See if we have valid contents
            if(!$im = @imagecreatefromstring($contents))
            {
                // Missing image or erroneous file image
                $error 2;
            } elseif($convert)
            {
                // Convert image
                if(!@imagejpeg($im$filename))
                {
                    // Error during saving
                    $error 3;
                }
            }
            else
            {
                // Save it
                if(@file_put_contents($filename$contents) === false)
                {
                    // Error during saving
                    $error 4;
                }
            }
            @imagedestroy($im);
            break;
        }

        if($error)
        {
            // Missing image or erroneous file image
            if($iei_remove_invalid_images && $iei_invalid_image_replacement)
            {
                $filename $iei_invalid_image_replacement;
                $error 0;
            }
        }

        // If we have a new image, save it
        if($newimage)
        {
            $images["$value"] = $bburl $filename;
            $oldurl $vbulletin->db->escape_string($value);
            $newurl $vbulletin->db->escape_string($images[$value]);
            $SQL "INSERT IGNORE INTO " TABLE_PREFIX "iei_img (
                oldurl, 
                newurl
                ) VALUES (
                '
$oldurl', 
                '
$newurl'
                )"
;
            $vbulletin->db->query_write($SQL);
        }

        if(!$error)
        {
            // Replace this image
            $changed true;
            $pagetext str_replace($matches[0][$key], '[img]' $images[$value] . '[/img]'$pagetext);
        }
    }

    if($changed)
    {
        $pagetext $vbulletin->db->escape_string($pagetext);
        $SQL "UPDATE " TABLE_PREFIX "post 
            SET pagetext='
$pagetext', 
                iei_parsed=1
            WHERE postid=
$rs[postid]";
        $fmt 'Changed Post: ';
    }
    else
    {
        $SQL "UPDATE " TABLE_PREFIX "post 
            SET iei_parsed=1
            WHERE postid=
$rs[postid]";
        $fmt 'Unchanged Post: ';
    }
    $fmt .= '<a href="%s/showthread.php?p=%d#post%d" target="_blank">%d</a>';
    $msg sprintf($fmt$bburl0$rs['postid'], $rs['postid'], $rs['postid']);
    $vbulletin->db->query_write($SQL);
    if($changed)
    {
        $SQL "DELETE 
            FROM " 
TABLE_PREFIX "postparsed 
            WHERE postid=
$rs[postid]";
        $vbulletin->db->query_write($SQL);
    }
    log_cron_action($msg$nextitem);

وابحث عن كلمة watermark تجد البيانات التي ادرجتها
PHP كود :
// بعد حفظ الصورة أو تحويلها
$file_with_path $filename;
 
// اسم الملف النهائي بعد الحفظ
$logo_path $iei_imported_images_folder '/logo.png';
@
watermark($file_with_path$extension$logo_path); 
مشكور اخوي
مافهمت الكود طويل ياليت تعطينا الكود كامل وحفظ الصوره تكون باامتداد الملف المرفوع
هذا تصحيح الكود السابق : 
PHP كود :
<?php

function watermark($filename$extension$logo) {
    // التحقق من وجود ملف الصورة الأصلي والشعار
    if (!file_exists($filename) || !file_exists($logo)) {
        return false;
    }

    $src_img null;

    // استخدام switch مع تطبيع الامتداد
    $extension strtolower($extension);
    switch ($extension) {
        case 'jpg':
        case 'jpeg':
            $src_img = @imagecreatefromjpeg($filename);
            break;
        case 'webp':
            if (function_exists('imagecreatefromwebp')) {
                $src_img = @imagecreatefromwebp($filename);
            }
            break;
        case 'png':
            $src_img = @imagecreatefrompng($filename);
            break;
        case 'gif':
            $src_img = @imagecreatefromgif($filename);
            break;
        default:
            // امتداد غير مدعوم
            return false;
    }

    // التحقق من نجاح إنشاء الصورة
    if (!$src_img) {
        return false;
    }

    // إنشاء صورة الشعار
    $src_logo = @imagecreatefrompng($logo);
    if (!$src_logo) {
        imagedestroy($src_img);
        return false;
    }

    // الحصول على الأبعاد
    $bwidth  imagesx($src_img);
    $bheight imagesy($src_img);
    $lwidth  imagesx($src_logo);
    $lheight imagesy($src_logo);

    // التحقق من أن الصورة كبيرة بما يكفي لوضع الشعار
    if ($bwidth $lwidth 10 && $bheight $lheight 10) {
        // حساب موقع الشعار (الزاوية اليمنى السفلية مع مسافة 5 بكسل)
        $src_x $bwidth - ($lwidth 5);
        $src_y $bheight - ($lheight 5);

        // دمج الصور
        imagealphablending($src_imgtrue);
        imagecopy($src_img$src_logo$src_x$src_y00$lwidth$lheight);

        // حفظ الصورة حسب الامتداد
        $saved false;
        switch ($extension) {
            case 'jpg':
            case 'jpeg':
                $saved = @imagejpeg($src_img$filename);
                break;
            case 'webp':
                if (function_exists('imagewebp')) {
                    $saved = @imagewebp($src_img$filename);
                }
                break;
            case 'png':
                $saved = @imagepng($src_img$filename);
                break;
            case 'gif':
                $saved = @imagegif($src_img$filename);
                break;
        }

        // تحرير الذاكرة
        imagedestroy($src_img);
        imagedestroy($src_logo);

        return $saved;
    }

    // الصورة صغيرة جداً
    imagedestroy($src_img);
    imagedestroy($src_logo);
    return false;
}

/*============================================================================*\
|| ########################################################################## ||
|| # Import External Images                                                 # ||
|| # ---------------------------------------------------------------------- # ||
|| # (C) Copyright Y2K Software s.a.s. 2010 - All Rights Reserved.          # ||
|| # This file may not be redistributed in whole or significant part.       # ||
|| ########################################################################## ||
\*============================================================================*/

/**
 * @author Y2K Software
 * @copyright (C) Copyright Y2K Software 2010 - All Rights Reserved
 * @version 1.0.2
 * @link www.pagerobot.com
 */

error_reporting(E_ALL & ~ E_NOTICE);
if(!
is_object($vbulletin->db))
{
    exit;
}

if (!
$vbulletin->options['mwaextraadmin5_setting_active_imgcache'])
{
    exit;
}

/**
 * iei_cache_registered_images()
 * 
 * Reads all registered images into memory for fast parsing.
 * If you have a large board, you may need to clean out this table from time to time by removing old records.
 * 
 * @return array $images
 */
function iei_cache_registered_images()
{
    global $vbulletin;

    $images = array();
    $SQL "SELECT oldurl, newurl 
        FROM " 
TABLE_PREFIX "iei_img";
    $rss $vbulletin->db->query_read($SQL);
    while($rs $vbulletin->db->fetch_array($rss))
    {
        $images["$rs[oldurl]"] = $rs['newurl'];
    }
    $vbulletin->db->free_result($rss);

    return $images;
}

/**
 * iei_normalize_path()
 * 
 * Avoid strange path names.
 * 
 * @param mixed $path
 * @return mixed $path
 */
function iei_normalize_path($path)
{
    if(substr($path, -11) != '/')
    {
        $path .= '/';
    }
    $path str_replace('\\''/'$path);
    if(strpos($path':'))
    {
        $path str_replace('//''/'$path);
    }

    return $path;
}

/**
 * iei_get_file_index()
 * 
 * Search a new file name.
 * 
 * @param mixed $path
 * @param mixed $extension
 * @return mixed $filename
 */
function iei_get_file_index(&$path, &$extension)
{
    for($i 1;; $i++)
    {
        $filename "$path/$i.$extension";
        if(!file_exists($filename))
        {
            return $filename;
        }
    }
}

/**
 * iei_get_file_extension()
 * 
 * Sanitize extension.
 * 
 * @param mixed $value
 * @param mixed $convert
 * @param mixed $extension
 * @return void
 */
function iei_get_file_extension(&$value, &$convert, &$extension)
{
    if(ALWAYS_CONVERT_IMAGES)
    {
        $convert true;
        $extension 'jpg';
        return;
    }

    $convert false;
    $i strrpos($value'.');
    if($i === false)
    {
        $convert true;
        $extension 'jpg';
        return;
    }

    $extension substr($value$i 1);
    if(strpos($extension'/') !== false || strpos($extension'&') !== false)
    {
        $convert true;
        $extension 'jpg';
    }

    $extension strtolower($extension);
}

/**
 * iei_get_contents()
 * 
 * Get file from remote site.
 * 
 * @param mixed $url
 * @return $contents / false on error
 */
function iei_get_contents(&$url)
{
    $ch 0;
    if(USE_CURL)
    {
        $ch = @curl_init($url);
        curl_setopt($chCURLOPT_BINARYTRANSFER1);
        curl_setopt($chCURLOPT_RETURNTRANSFER1);
        curl_setopt($chCURLOPT_FAILONERROR1);
        curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        curl_setopt($chCURLOPT_CONNECTTIMEOUT10);
        curl_setopt($chCURLOPT_TIMEOUT120);
        curl_setopt($chCURLOPT_REFERERAEI_BBURL '/');
        curl_setopt($chCURLOPT_USERAGENTAEI_FORUMDOMAIN);
        $contents = @curl_exec($ch);
        @curl_close($ch);
    }
    if(!$ch)
    {
        // If CURL didn't work, try it differently
        $contents = @file_get_contents($imagename);
    }

    return $contents $contents false;
}

// Get iei options
define('USE_CURL'function_exists('curl_init'));
foreach(
$vbulletin->options as $key => $value)
{
    if(strpos($key'iei_') === false)
    {
        continue;
    }
    $$key $value;
}
define('ALWAYS_CONVERT_IMAGES'$iei_always_convert_images);

// Adjust options
$bburl0 $vbulletin->options['bburl'];
if(
$iei_bburl_replacement)
{
    $bburl $iei_bburl_replacement '/';
}
else
{
    $bburl $bburl0 '/';
}
$iei_imported_images_folder iei_normalize_path($iei_imported_images_folder);
$iei_ignore explode("\r\n"$iei_ignore);
$iei_ignore[] = $bburl;
$iei_ignore[] = $bburl0 '/';
$iei_ignore[] = $iei_imported_images_folder;
if(
$iei_remove_invalid_images)
{
    $iei_ignore[] = $iei_invalid_image_replacement;
}

// Exclude all new records which have no images at all
$SQL "UPDATE " TABLE_PREFIX "post 
    SET iei_parsed=1
    WHERE iei_parsed=0
        AND NOT pagetext LIKE '%[/IMG]%'"
;
$vbulletin->db->query_write($SQL);

$mwaimgcache_mwanotforumid "AND thread.forumid NOT IN (0)";
$iei_ignore_usersp "AND post.userid NOT IN (0)";

if (
$vbulletin->options['mwaimgcache_mwanotforumid'])
{
$mwaimgcache_mwanotforumid "AND thread.forumid NOT IN (" $vbulletin->options['mwaimgcache_mwanotforumid'] . ")";
}

if (
$vbulletin->options['iei_ignore_users'])
{
$iei_ignore_usersp "AND post.userid NOT IN (" $vbulletin->options['iei_ignore_users'] . ")";
}

// For each record with images ...
$cnt 0;
$SQL "SELECT post.postid, post.userid, post.dateline, post.pagetext , post.iei_parsed
    FROM " 
TABLE_PREFIX "post AS post
    LEFT JOIN " 
TABLE_PREFIX "thread AS thread ON(thread.threadid = post.threadid)
    WHERE post.iei_parsed=0
        
$mwaimgcache_mwanotforumid
        
$iei_ignore_usersp
        AND post.pagetext LIKE '%[/IMG]%'
    ORDER BY post.dateline DESC"
;

$rss $vbulletin->db->query_read($SQL);
while(
$rs $vbulletin->db->fetch_array($rss))
{
    $cnt++;
    if($cnt $iei_max_post_count)
    {
        break;
    }
    if($cnt == 1)
    {
        // Cache registered images
        $images iei_cache_registered_images();
    }

    $pagetext $rs['pagetext'];

    // Find all embedded images
    if(!preg_match_all('/\[img.*?\](.*?)\[\/img\]/is'$pagetext$matches))
    {
        $SQL "UPDATE " TABLE_PREFIX "post 
            SET iei_parsed=1
            WHERE postid=
$rs[postid]";
        $vbulletin->db->query_write($SQL);
        continue;
    }

    $changed false;
    foreach($matches[1] as $key => $value)
    {
        $error 0;

        // Search for images to be ignored
        $ignore false;
        foreach($iei_ignore as $ivalue)
        {
            if($value && $ivalue && strpos($value$ivalue) !== false)
            {
                $ignore true;
                break;
            }
        }
        if($ignore)
        {
            continue;
        }

        // If we haven't got the image yet, download
        $filename $images["$value"];
        $newimage = !$filename;
        while($newimage)
        {
            // Get file from remote site
            if(!$contents iei_get_contents($value))
            {
                // Missing contents
                $error 1;
                break;
            }

            // Get file extension
            iei_get_file_extension($value$convert$extension);
            
            
// Make path
            $path $iei_imported_images_folder date('Y/m'$rs['dateline']);
            @mkdir($path0755true);

            // Get file index
            $filename iei_get_file_index($path$extension);

            // See if we have valid contents
            if(!$im = @imagecreatefromstring($contents))
            {
                // Missing image or erroneous file image
                $error 2;
            
            elseif($convert)
            {
                // Convert image
                if(!@imagejpeg($im$filename))
                {
                    // Error during saving
                    $error 3;
                }
            }
            else
            {
                // Save it
                if(@file_put_contents($filename$contents) === false)
                {
                    // Error during saving
                    $error 4;
                }
            }
            
            
// **** إضافة العلامة المائية ****
            // إذا لم يحدث خطأ في الحفظ، وقمنا بإنشاء الصورة بنجاح
            if (!$error && isset($im) && $im) {
                // تحديد مسار ملف الشعار
                $logo_path rtrim($iei_imported_images_folder'/') . '/logo.png';
                
                
// استدعاء دالة العلامة المائية
                watermark($filename$extension$logo_path);
            }
            
            
@imagedestroy($im);
            break;
        }

        if($error)
        {
            // Missing image or erroneous file image
            if($iei_remove_invalid_images && $iei_invalid_image_replacement)
            {
                $filename $iei_invalid_image_replacement;
                $error 0;
            }
        }

        // If we have a new image, save it
        if($newimage)
        {
            $images["$value"] = $bburl $filename;
            $oldurl $vbulletin->db->escape_string($value);
            $newurl $vbulletin->db->escape_string($images[$value]);
            $SQL "INSERT IGNORE INTO " TABLE_PREFIX "iei_img (
                oldurl, 
                newurl
                ) VALUES (
                '
$oldurl', 
                '
$newurl'
                )"
;
            $vbulletin->db->query_write($SQL);
        }

        if(!$error)
        {
            // Replace this image
            $changed true;
            $pagetext str_replace($matches[0][$key], '[img]' $images[$value] . '[/img]'$pagetext);
        }
    }

    if($changed)
    {
        $pagetext $vbulletin->db->escape_string($pagetext);
        $SQL "UPDATE " TABLE_PREFIX "post 
            SET pagetext='
$pagetext', 
                iei_parsed=1
            WHERE postid=
$rs[postid]";
        $fmt 'Changed Post: ';
    }
    else
    {
        $SQL "UPDATE " TABLE_PREFIX "post 
            SET iei_parsed=1
            WHERE postid=
$rs[postid]";
        $fmt 'Unchanged Post: ';
    }
    $fmt .= '<a href="%s/showthread.php?p=%d#post%d" target="_blank">%d</a>';
    $msg sprintf($fmt$bburl0$rs['postid'], $rs['postid'], $rs['postid']);
    $vbulletin->db->query_write($SQL);
    if($changed)
    {
        $SQL "DELETE 
            FROM " 
TABLE_PREFIX "postparsed 
            WHERE postid=
$rs[postid]";
        $vbulletin->db->query_write($SQL);
    }
    log_cron_action($msg$nextitem);
}
?>

و هذا مثال اخر و مختصر : يمكنك تجربته 
PHP كود :
<?php

function watermark($filename$extension$logo){

    if ($extension == 'jpg' || $extension == 'jpeg') {
        $src_img imagecreatefromjpeg($filename);
    } elseif ($extension == 'png') {
        $src_img imagecreatefrompng($filename);
    } elseif ($extension == 'gif') {
        $src_img imagecreatefromgif($filename);
    } elseif ($extension == 'webp') {
        $src_img imagecreatefromwebp($filename);
    } else {
        return false;
    }

    $src_logo imagecreatefrompng($logo);

    $bwidth  imagesx($src_img);
    $bheight imagesy($src_img);
    $lwidth  imagesx($src_logo);
    $lheight imagesy($src_logo);

    // مكان الشعار (أسفل يمين)
    $dst_x $bwidth $lwidth 10;
    $dst_y $bheight $lheight 10;

    imagealphablending($src_imgtrue);
    imagesavealpha($src_imgtrue);

    imagecopy($src_img$src_logo$dst_x$dst_y00$lwidth$lheight);

    // حفظ بنفس الامتداد
    if ($extension == 'jpg' || $extension == 'jpeg') {
        imagejpeg($src_img$filename90);
    } elseif ($extension == 'png') {
        imagepng($src_img$filename);
    } elseif ($extension == 'gif') {
        imagegif($src_img$filename);
    } elseif ($extension == 'webp') {
        imagewebp($src_img$filename);
    }

    imagedestroy($src_img);
    imagedestroy($src_logo);
}


// ==============================
// تحميل الصورة من رابط
// ==============================

$url "https://example.com/image.jpg"// رابط الصورة

// استخراج الامتداد
$ext strtolower(pathinfo($urlPATHINFO_EXTENSION));

// لو الامتداد غير معروف
if (!$ext) {
    $ext 'jpg';
}

// اسم الملف
$filename "images/" time() . "." $ext;

// تحميل الصورة
$content file_get_contents($url);
file_put_contents($filename$content);

// ==============================
// إضافة الشعار
// ==============================

$logo "images/logo.png"// مسار الشعار
watermark($filename$ext$logo);

echo 
"تم تحميل الصورة وختمها بنجاح";
?>
أسف
بعد تجربة رابط آخر
تم ختم الصوره بنجاح بالكود الاول
تستاهل افظل تقييم
فيه ملاحظات بسيطه على الكود
الكاش لاينقل الصوره من نوع webp
ولا ينقل الصور من موقع يستعمل ssl
فاليت تحل لي المشكله بارك الله فيك
(01-04-26, 07:47 AM)nnnjk كتب : [ -> ]فيه ملاحظات بسيطه على الكود
الكاش لاينقل الصوره من نوع webp
ولا ينقل الصور من موقع يستعمل ssl
فاليت تحل لي المشكله بارك الله فيك

PHP كود :
<?php
function watermark($filename$extension$logo) {
    // التحقق من وجود ملف الصورة الأصلي والشعار
    if (!file_exists($filename) || !file_exists($logo)) {
        return false;
    }
    $src_img null;
    // استخدام switch مع تطبيع الامتداد
    $extension strtolower($extension);
    switch ($extension) {
        case 'jpg':
        case 'jpeg':
            $src_img = @imagecreatefromjpeg($filename);
            break;
        case 'webp':
            if (function_exists('imagecreatefromwebp')) {
                $src_img = @imagecreatefromwebp($filename);
            }
            break;
        case 'png':
            $src_img = @imagecreatefrompng($filename);
            break;
        case 'gif':
            $src_img = @imagecreatefromgif($filename);
            break;
        default:
            // امتداد غير مدعوم
            return false;
    }
    // التحقق من نجاح إنشاء الصورة
    if (!$src_img) {
        return false;
    }
    // إنشاء صورة الشعار
    $src_logo = @imagecreatefrompng($logo);
    if (!$src_logo) {
        imagedestroy($src_img);
        return false;
    }
    // الحصول على الأبعاد
    $bwidth  imagesx($src_img);
    $bheight imagesy($src_img);
    $lwidth  imagesx($src_logo);
    $lheight imagesy($src_logo);
    // التحقق من أن الصورة كبيرة بما يكفي لوضع الشعار
    if ($bwidth $lwidth 10 && $bheight $lheight 10) {
        // حساب موقع الشعار (الزاوية اليمنى السفلية مع مسافة 5 بكسل)
        $src_x $bwidth - ($lwidth 5);
        $src_y $bheight - ($lheight 5);
        // دمج الصور
        imagealphablending($src_imgtrue);
        imagecopy($src_img$src_logo$src_x$src_y00$lwidth$lheight);
        // حفظ الصورة حسب الامتداد
        $saved false;
        switch ($extension) {
            case 'jpg':
            case 'jpeg':
                $saved = @imagejpeg($src_img$filename90);
                break;
            case 'webp':
                if (function_exists('imagewebp')) {
                    $saved = @imagewebp($src_img$filename90);
                }
                break;
            case 'png':
                $saved = @imagepng($src_img$filename9);
                break;
            case 'gif':
                $saved = @imagegif($src_img$filename);
                break;
        }
        // تحرير الذاكرة
        imagedestroy($src_img);
        imagedestroy($src_logo);
        return $saved;
    }
    // الصورة صغيرة جداً
    imagedestroy($src_img);
    imagedestroy($src_logo);
    return false;
}
/*============================================================================*\
|| ########################################################################## ||
|| # Import External Images                                                 # ||
|| # ---------------------------------------------------------------------- # ||
|| # (C) Copyright Y2K Software s.a.s. 2010 - All Rights Reserved.          # ||
|| # This file may not be redistributed in whole or significant part.       # ||
|| ########################################################################## ||
\*============================================================================*/
/**
 * @author Y2K Software
 * @copyright (C) Copyright Y2K Software 2010 - All Rights Reserved
 * @version 1.0.2
 * @link www.pagerobot.com
 */
error_reporting(E_ALL & ~ E_NOTICE);
if(!
is_object($vbulletin->db))
{
    exit;
}
if (!
$vbulletin->options['mwaextraadmin5_setting_active_imgcache'])
{
    exit;
}
/**
 * iei_cache_registered_images()
 * 
 * Reads all registered images into memory for fast parsing.
 * If you have a large board, you may need to clean out this table from time to time by removing old records.
 * 
 * @return array $images
 */
function iei_cache_registered_images()
{
    global $vbulletin;
    $images = array();
    $SQL "SELECT oldurl, newurl 
        FROM " 
TABLE_PREFIX "iei_img";
    $rss $vbulletin->db->query_read($SQL);
    while($rs $vbulletin->db->fetch_array($rss))
    {
        $images["$rs[oldurl]"] = $rs['newurl'];
    }
    $vbulletin->db->free_result($rss);
    return $images;
}
/**
 * iei_normalize_path()
 * 
 * Avoid strange path names.
 * 
 * @param mixed $path
 * @return mixed $path
 */
function iei_normalize_path($path)
{
    if(substr($path, -11) != '/')
    {
        $path .= '/';
    }
    $path str_replace('\\''/'$path);
    if(strpos($path':'))
    {
        $path str_replace('//''/'$path);
    }
    return $path;
}
/**
 * iei_get_file_index()
 * 
 * Search a new file name.
 * 
 * @param mixed $path
 * @param mixed $extension
 * @return mixed $filename
 */
function iei_get_file_index(&$path, &$extension)
{
    for($i 1;; $i++)
    {
        $filename "$path/$i.$extension";
        if(!file_exists($filename))
        {
            return $filename;
        }
    }
}
/**
 * iei_get_file_extension()
 * 
 * Sanitize extension.
 * 
 * @param mixed $value
 * @param mixed $convert
 * @param mixed $extension
 * @return void
 */
function iei_get_file_extension(&$value, &$convert, &$extension)
{
    if(ALWAYS_CONVERT_IMAGES)
    {
        $convert true;
        $extension 'jpg';
        return;
    }
    $convert false;
    $i strrpos($value'.');
    if($i === false)
    {
        $convert true;
        $extension 'jpg';
        return;
    }
    $extension substr($value$i 1);
    // إزالة أي معلمات بعد الامتداد
    if(strpos($extension'?') !== false) {
        $extension substr($extension0strpos($extension'?'));
    }
    if(strpos($extension'/') !== false || strpos($extension'&') !== false)
    {
        $convert true;
        $extension 'jpg';
    }
    $extension strtolower($extension);
    
    
// دعم WebP
    if($extension == 'webp' && function_exists('imagecreatefromwebp')) {
        $convert false;
    }
}
/**
 * iei_get_contents()
 * 
 * Get file from remote site with SSL support.
 * 
 * @param mixed $url
 * @return $contents / false on error
 */
function iei_get_contents(&$url)
{
    $contents false;
    
    
// محاولة باستخدام cURL (يدعم SSL)
    if(USE_CURL)
    {
        $ch = @curl_init($url);
        if($ch) {
            curl_setopt($chCURLOPT_BINARYTRANSFER1);
            curl_setopt($chCURLOPT_RETURNTRANSFER1);
            curl_setopt($chCURLOPT_FAILONERROR1);
            curl_setopt($chCURLOPT_FOLLOWLOCATION1);
            curl_setopt($chCURLOPT_CONNECTTIMEOUT30);
            curl_setopt($chCURLOPT_TIMEOUT120);
            curl_setopt($chCURLOPT_REFERERAEI_BBURL '/');
            curl_setopt($chCURLOPT_USERAGENTAEI_FORUMDOMAIN);
            curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse); // تعطيل التحقق من SSL لبعض المواقع
            curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
            $contents = @curl_exec($ch);
            $http_code = @curl_getinfo($chCURLINFO_HTTP_CODE);
            @curl_close($ch);
            
            
// إذا فشل cURL أو كان هناك خطأ SSL
            if($contents === false || $http_code != 200) {
                $contents false;
            }
        }
    }
    
    
// إذا فشل cURL، نحاول باستخدام file_get_contents مع سياق SSL
    if(!$contents && function_exists('stream_context_create'))
    {
        $context stream_context_create([
            'ssl' => [
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            
],
            'http' => [
                'timeout' => 30,
                'user_agent' => AEI_FORUMDOMAIN,
                'header' => "Referer: " AEI_BBURL "/\r\n"
            ]
        ]);
        
        $contents 
= @file_get_contents($urlfalse$context);
    }
    
    
// محاولة أخيرة باستخدام file_get_contents العادية
    if(!$contents)
    {
        $contents = @file_get_contents($url);
    }
    return $contents $contents false;
}
// Get iei options
define('USE_CURL'function_exists('curl_init'));
foreach(
$vbulletin->options as $key => $value)
{
    if(strpos($key'iei_') === false)
    {
        continue;
    }
    $$key $value;
}
define('ALWAYS_CONVERT_IMAGES'$iei_always_convert_images);
// Adjust options
$bburl0 $vbulletin->options['bburl'];
if(
$iei_bburl_replacement)
{
    $bburl $iei_bburl_replacement '/';
}
else
{
    $bburl $bburl0 '/';
}
$iei_imported_images_folder iei_normalize_path($iei_imported_images_folder);
$iei_ignore explode("\r\n"$iei_ignore);
$iei_ignore[] = $bburl;
$iei_ignore[] = $bburl0 '/';
$iei_ignore[] = $iei_imported_images_folder;
if(
$iei_remove_invalid_images)
{
    $iei_ignore[] = $iei_invalid_image_replacement;
}
// Exclude all new records which have no images at all
$SQL "UPDATE " TABLE_PREFIX "post 
    SET iei_parsed=1
    WHERE iei_parsed=0
        AND NOT pagetext LIKE '%[/IMG]%'"
;
$vbulletin->db->query_write($SQL);
$mwaimgcache_mwanotforumid "AND thread.forumid NOT IN (0)";
$iei_ignore_usersp "AND post.userid NOT IN (0)";
if (
$vbulletin->options['mwaimgcache_mwanotforumid'])
{
$mwaimgcache_mwanotforumid "AND thread.forumid NOT IN (" $vbulletin->options['mwaimgcache_mwanotforumid'] . ")";
}
if (
$vbulletin->options['iei_ignore_users'])
{
$iei_ignore_usersp "AND post.userid NOT IN (" $vbulletin->options['iei_ignore_users'] . ")";
}
// For each record with images ...
$cnt 0;
$SQL "SELECT post.postid, post.userid, post.dateline, post.pagetext , post.iei_parsed
    FROM " 
TABLE_PREFIX "post AS post
    LEFT JOIN " 
TABLE_PREFIX "thread AS thread ON(thread.threadid = post.threadid)
    WHERE post.iei_parsed=0
        
$mwaimgcache_mwanotforumid
        
$iei_ignore_usersp
        AND post.pagetext LIKE '%[/IMG]%'
    ORDER BY post.dateline DESC"
;
$rss $vbulletin->db->query_read($SQL);
while(
$rs $vbulletin->db->fetch_array($rss))
{
    $cnt++;
    if($cnt $iei_max_post_count)
    {
        break;
    }
    if($cnt == 1)
    {
        // Cache registered images
        $images iei_cache_registered_images();
    }
    $pagetext $rs['pagetext'];
    // Find all embedded images
    if(!preg_match_all('/\[img.*?\](.*?)\[\/img\]/is'$pagetext$matches))
    {
        $SQL "UPDATE " TABLE_PREFIX "post 
            SET iei_parsed=1
            WHERE postid=
$rs[postid]";
        $vbulletin->db->query_write($SQL);
        continue;
    }
    $changed false;
    foreach($matches[1] as $key => $value)
    {
        $error 0;
        // Search for images to be ignored
        $ignore false;
        foreach($iei_ignore as $ivalue)
        {
            if($value && $ivalue && strpos($value$ivalue) !== false)
            {
                $ignore true;
                break;
            }
        }
        if($ignore)
        {
            continue;
        }
        // If we haven't got the image yet, download
        $filename $images["$value"];
        $newimage = !$filename;
        while($newimage)
        {
            // Get file from remote site
            if(!$contents iei_get_contents($value))
            {
                // Missing contents
                $error 1;
                break;
            }
            // Get file extension
            iei_get_file_extension($value$convert$extension);
            
            
// Make path
            $path $iei_imported_images_folder date('Y/m'$rs['dateline']);
            @mkdir($path0755true);
            // Get file index
            $filename iei_get_file_index($path$extension);
            // See if we have valid contents
            if(!$im = @imagecreatefromstring($contents))
            {
                // Missing image or erroneous file image
                $error 2;
            
            elseif($convert)
            {
                // Convert image
                if(!@imagejpeg($im$filename90))
                {
                    // Error during saving
                    $error 3;
                }
            }
            else
            {
                // Save it
                if(@file_put_contents($filename$contents) === false)
                {
                    // Error during saving
                    $error 4;
                }
            }
            
            
// **** إضافة العلامة المائية ****
            // إذا لم يحدث خطأ في الحفظ، وقمنا بإنشاء الصورة بنجاح
            if (!$error && isset($im) && $im) {
                // تحديد مسار ملف الشعار
                $logo_path rtrim($iei_imported_images_folder'/') . '/logo.png';
                
                
// استدعاء دالة العلامة المائية
                watermark($filename$extension$logo_path);
            }
            
            
@imagedestroy($im);
            break;
        }
        if($error)
        {
            // Missing image or erroneous file image
            if($iei_remove_invalid_images && $iei_invalid_image_replacement)
            {
                $filename $iei_invalid_image_replacement;
                $error 0;
            }
        }
        // If we have a new image, save it
        if($newimage)
        {
            $images["$value"] = $bburl $filename;
            $oldurl $vbulletin->db->escape_string($value);
            $newurl $vbulletin->db->escape_string($images[$value]);
            $SQL "INSERT IGNORE INTO " TABLE_PREFIX "iei_img (
                oldurl, 
                newurl
                ) VALUES (
                '
$oldurl', 
                '
$newurl'
                )"
;
            $vbulletin->db->query_write($SQL);
        }
        if(!$error)
        {
            // Replace this image
            $changed true;
            $pagetext str_replace($matches[0][$key], '[img]' $images[$value] . '[/img]'$pagetext);
        }
    }
    if($changed)
    {
        $pagetext $vbulletin->db->escape_string($pagetext);
        $SQL "UPDATE " TABLE_PREFIX "post 
            SET pagetext='
$pagetext', 
                iei_parsed=1
            WHERE postid=
$rs[postid]";
        $fmt 'Changed Post: ';
    }
    else
    {
        $SQL "UPDATE " TABLE_PREFIX "post 
            SET iei_parsed=1
            WHERE postid=
$rs[postid]";
        $fmt 'Unchanged Post: ';
    }
    $fmt .= '<a href="%s/showthread.php?p=%d#post%d" target="_blank">%d</a>';
    $msg sprintf($fmt$bburl0$rs['postid'], $rs['postid'], $rs['postid']);
    $vbulletin->db->query_write($SQL);
    if($changed)
    {
        $SQL "DELETE 
            FROM " 
TABLE_PREFIX "postparsed 
            WHERE postid=
$rs[postid]";
        $vbulletin->db->query_write($SQL);
    }
    log_cron_action($msg$nextitem);
}
?>

اذا اردت التحقق : 
PHP كود :
<?php
if (function_exists('imagecreatefromwebp')) {
    echo "WebP مدعوم";
} else {
    echo "WebP غير مدعوم، يرجى تثبيت مكتبة GD مع دعم WebP";
}
?>
يعطيك العافيه لم ينقل الصوره من نوع webp ولا الصور التي تستخدم ssl واستبدل الصور المذكوره بصورة الصوره غير موجوده

وعند تشغيل الكرون لهذه الاضافه تخرج صفحة خطأ
Service Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

بعد ادراج الكود الثاني في ملف انديكس
طبع WebP مدعوم
PHP كود :
<?php
@set_time_limit(0);
@
ini_set('memory_limit''512M');

function 
download_image($url) {
    $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_HTTPHEADER => [
            'Accept: image/webp,image/*,*/*;q=0.8'
        ],
        CURLOPT_USERAGENT => 'Mozilla/5.0'
    ]);

    $data curl_exec($ch);
    $http curl_getinfo($chCURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($http != 200 || !$data) {
        return false;
    }

    return $data;
}

function 
watermark($file$ext$logo) {

    if (!file_exists($file) || !file_exists($logo)) return false;

    $ext strtolower($ext);

    // تحميل الصورة
    switch ($ext) {
        case 'jpg':
        case 'jpeg':
            $img = @imagecreatefromjpeg($file);
            break;

        case 'png':
            $img = @imagecreatefrompng($file);
            break;

        case 'gif':
            $img = @imagecreatefromgif($file);
            break;

        case 'webp':
            if (function_exists('imagecreatefromwebp')) {
                $img = @imagecreatefromwebp($file);
            } else {
                return false;
            }
            break;

        default:
            return false;
    }

    if (!$img) return false;

    $logo_img = @imagecreatefrompng($logo);
    if (!$logo_img) return false;

    $bw imagesx($img);
    $bh imagesy($img);
    $lw imagesx($logo_img);
    $lh imagesy($logo_img);

    if ($bw $lw 10 || $bh $lh 10) return false;

    $x $bw $lw 5;
    $y $bh $lh 5;

    imagealphablending($imgtrue);
    imagecopy($img$logo_img$x$y00$lw$lh);

    // حفظ الصورة
    switch ($ext) {
        case 'jpg':
        case 'jpeg':
            imagejpeg($img$file90);
            break;

        case 'png':
            imagepng($img$file9);
            break;

        case 'gif':
            imagegif($img$file);
            break;

        case 'webp':
            imagewebp($img$file90);
            break;
    }

    imagedestroy($img);
    imagedestroy($logo_img);

    return true;
}

function 
process_image($url$save_path$logo) {

    // تحميل الصورة
    $data download_image($url);
    if (!$data) return false;

    // استخراج الامتداد
    $ext strtolower(pathinfo(parse_url($urlPHP_URL_PATH), PATHINFO_EXTENSION));

    if (!$ext$ext 'jpg';

    // دعم WebP
    if (!in_array($ext, ['jpg','jpeg','png','gif','webp'])) {
        $ext 'jpg';
    }

    // إنشاء المجلد
    if (!is_dir(dirname($save_path))) {
        mkdir(dirname($save_path), 0755true);
    }

    $file $save_path '.' $ext;

    // حفظ أولي
    file_put_contents($file$data);

    // تحقق من الصورة
    $img = @imagecreatefromstring($data);

    // إذا فشل (خصوصاً WebP)
    if (!$img && $ext == 'webp' && function_exists('imagecreatefromwebp')) {
        $img = @imagecreatefromwebp($file);
    }

    if (!$img) {
        unlink($file);
        return false;
    }

    imagedestroy($img);

    // إضافة watermark
    watermark($file$ext$logo);

    return $file;
}
?>

طريقة الاستخدام : 
PHP كود :
$url "https://example.com/image.webp";
$save "uploads/2026/04/img_1";
$logo "uploads/logo.png";

$result process_image($url$save$logo);

if (
$result) {
    echo "تم الحفظ: " $result;
} else {
    echo "فشل";


جرّب و خبرني
يعطيك العافيه
تعطل الكاش لم يعد ينقل الصور نهائيا
على العموم الكاش يعمل على استضافه اخرى بدون مشاكل
الصفحات : 1 2 3 4 5