مشکل با gd توی لینوکس

moein7tl

Member
من یه کلاس نوشتم واسه Captcha Code توی ویندوز لوکال کامل اجرا می شه،ولی همون توی هاست لینوکس یا لوکال لینوکس نمی یاد.میگه
The image cannot be displayed because it contains errors.
 

Domanjiri

Well-Known Member
سلام

کدهای سازنده ی تصویر، که تمامن (به جای تماماً!) php هستند رو در یک فایل و بخشی از کدها که شامل کدهای html هست رو در فایل دیگه ای قرار بدین. اگه مشکل حل نشد، لطفن کدتون رو اینجا بزارید ( اون بخشی که تصویر رو تولید می کنه، نه کل 600 خط رو!) تا با هم بررسی کنیم ِش!

موفق باشین
 

moein7tl

Member
PHP:
    public function draw(){
        /*
         * to draw Image of the captcha code
         */
        if ($this->BackgroundImage === null){
            if ($this->Color_B === null || $this->Color_B === null || $this->Color_B === null ){
                if ($this->TC_B === null || $this->TC_B === null || $this->TC_B === null)
                        $this->SetTextColor(0, 0, 0);
                //if obj doen't have background image,background color and text color,it will be set as 0, 0, 0
            } else {
                if ($this->TC_B === null || $this->TC_B === null || $this->TC_B === null){
                        $this->RGB2HSL();
                        $this->HSL2RGB();
                        //if obj doesn't have backgorund image,but have background color,and dont have textcolor,it will be set by XPart:D
                }
            }
        } else {
            if ($this->Color_B === null || $this->Color_B === null || $this->Color_B === null ){
                $this->getImageMainRGB(); // if obj doesn't background Image,but dont have background color,it will be set by this method
                if ($this->TC_B === null || $this->TC_B === null || $this->TC_B === null){
                        $this->RGB2HSL();
                        $this->HSL2RGB();
                        //if obj doesn't have TextColor ,it will be set by XPart:D
                }
            } else {
                if ($this->TC_B === null || $this->TC_B === null || $this->TC_B === null){
                        $this->RGB2HSL();
                        $this->HSL2RGB();
                        //XPart again,if TextColor doesnt set,but Background color set
                }
            }
        }
        // End of Set Background and Text Color
        $this->setFontCanBeUseSRC();//make random font
        
        if ($this->BackgroundImage != null){//have background
            //create image
            switch ($this->ImageSuffix){
                case 'gif':
                    $im = imagecreatefromgif($this->BackgroundImage);
                    break;
                case 'jpg':
                    $im = imagecreatefromjpeg($this->BackgroundImage);
                    break;
                case 'png':
                default:
                    $im = imagecreatefrompng($this->BackgroundImage);
            }
            $this->width = imagesx($im);
            $this->height= imagesy($im);
        } else {    //dont have background
            $im = imagecreatetruecolor($this->width, $this->height);
            if (!($this->Color_R === null || $this->Color_G === null || $this->Color_B === null)){
                $color_Back = imagecolorallocate($im, $this->Color_R , $this->Color_G, $this->Color_B);
                imagefilledrectangle($im, 0, 0, $this->width, $this->height, $color_Back);
            } else {
                //with out background (transparnet image)
                imagealphablending($im, false);
                $col=imagecolorallocatealpha($im,255,255,255,127);
                //Create overlapping 100x50 transparent layer
                imagefilledrectangle($im,0,0,$this->width, $this->height,$col);
                //Continue to keep layers transparent
                imagealphablending($im,true);
            }
        }
        $color_Text = imagecolorallocate($im, $this->TC_R , $this->TC_G, $this->TC_B);//make text color by RGB
        $count = strlen($this->Text);
        $XSize =   ($this->width / $count + 5);
        
        for ($i = 0; $i < $count; $i++){
            $char = substr($this->Text,$i,1);
            $font = $this->getFontSRC();
            $angle = $this->randangle();
            $array = $this->getFontSize_Position($font, $char, $angle,  $XSize);
            imagefttext($im, $array['size'], $angle,  $i * ($XSize - 5) + 5, $array['YPos'], $color_Text,$font, $char);
            //draw a char into image
        }
        
        switch ($this->ImageSuffix){
        //send header and draw image
            case 'jpg':
                header('Content-type: image/jpeg');
                imagejpeg($im);
                break;
            case 'gif':
                header('Content-type: image/gif');
                imagegif($im);
                break;
            case 'png':
                header('Content-type: image/png');
                imagepng($im);
                break;
               default:
                imagesavealpha($im,true);
                imagepng($im,"MoeinCaptchaTranspartImage.png",1);
                header("Content-Type: image/png");
                readfile("MoeinCaptchaTranspartImage.png");
                break;
        }
        //release a memory
کد html نداره،یه کلاس و متد draw اون کار کشیدن شکل رو انجام می ده
واسه درست کردن Captcha کده
 
آخرین ویرایش:

Domanjiri

Well-Known Member
درود بر شما

تست کردن این کلاس کمی زمان میبره، ولی بعید می دونم مشکل از این باشه، پس این مورد رو میذاریم به عنوان آخرین راه حل!

شما این تصاویر رو با چه فرمتی می سازید؟ یه تصویر دیگه با همون فرمت رو روی سرور آپلود کنید و با لینک مستقیم اونو فراخوانی کنید، مثلن:
کد:
http://www.example.com/sample.png
ببینید دوباره همون اررور نشون داده میشه یا نه.

موفق باشین
 

Domanjiri

Well-Known Member
دورد بر شما

یه phpinfo بگیرید از سرور بگیرید، ببینید که GD نسخه 2 نصب هست یا نه! باید همچین چیزی باشه:
کد:
[LEFT]gd
GD Support enabled
GD Version 2.xxx
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled[/LEFT]

موفق باشین
 

moein7tl

Member

GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.2.1
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XPM Support enabled​
XBM Support enabled
 

Domanjiri

Well-Known Member
درود بر شما

شما کد زیر رو توی یه فایل بریزید و روی سرور اجراش کنید، اگه تصویری نشون نداد، که مشکل از سرور هست، در غیر اینصورت میریم سراغ کدتون! (اینم از آخرین تیر خشاب من!:green:)
PHP:
<?php
$size = 300;
$image=imagecreatetruecolor($size, $size);

// something to get a white background with black border
$back = imagecolorallocate($image, 255, 255, 255);
$border = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image, 0, 0, $size - 1, $size - 1, $back);
imagerectangle($image, 0, 0, $size - 1, $size - 1, $border);

$yellow_x = 100;
$yellow_y = 75;
$red_x    = 120;
$red_y    = 165;
$blue_x   = 187;
$blue_y   = 125;
$radius   = 150;

// allocate colors with alpha values
$yellow = imagecolorallocatealpha($image, 255, 255, 0, 75);
$red    = imagecolorallocatealpha($image, 255, 0, 0, 75);
$blue   = imagecolorallocatealpha($image, 0, 0, 255, 75);

// drawing 3 overlapped circle
imagefilledellipse($image, $yellow_x, $yellow_y, $radius, $radius, $yellow);
imagefilledellipse($image, $red_x, $red_y, $radius, $radius, $red);
imagefilledellipse($image, $blue_x, $blue_y, $radius, $radius, $blue);

// don't forget to output a correct header!
header('Content-Type: image/png');

// and finally, output the result
imagepng($image);
imagedestroy($image);

در ضمن اگه هنوز سایتتون کامل راه اندازی نشده، ارور ریپورتینگ رو :
PHP:
error_reporting(E_ALL);
قرار بدین و فایل log سرور رو مطالعه کنید، شاید مفید باشه!

موفق باشین
 

moein7tl

Member
آقا مشکل حل شد . مرسی
مشکل از permission های لینوکس بود
شما یه نیگاه بکن captcha.printf.ir اگه ارزشش رو داره بذارم واسه دانلود
فکر کنم چیز بدی نشده باشه
 

Domanjiri

Well-Known Member
زنده باشید

آقا من به هیچ وجه فکر نمی کردم که پرمیشن لازم برای ذخیره تصویر رو تنظیم نکرده باشین، پس یه جورایی سر کار بودیم [شوخی !] :green:

در هر صورت خوشحالم که مشکلتون برطرف شد، کدی که نوشتین هم قابلیت گسترش خوبی داره،

ارزشش رو داره بذارم واسه دانلود
هر طور که شما خودتون مایل هستید!

موفق باشین:rose:
 

moein7tl

Member
زنده باشید

آقا من به هیچ وجه فکر نمی کردم که پرمیشن لازم برای ذخیره تصویر رو تنظیم نکرده باشین، پس یه جورایی سر کار بودیم [شوخی !] :green:

در هر صورت خوشحالم که مشکلتون برطرف شد، کدی که نوشتین هم قابلیت گسترش خوبی داره،


هر طور که شما خودتون مایل هستید!

موفق باشین:rose:

شرمنده :دی اصلا حواسم بهش نبود:دی
همش فکر می کردم یه جایی دارم خروجی می دم که نمی یاد:دی
 

جدیدترین ارسال ها

بالا