Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Skrypt Demotywatorów
#1
Chciałbym abyście mi pomogli w skrypcie demotywatorów który znalazłem na internecie na stronie http://www.letsgeek.com/code/motivational-poster-generator-script/ .

Chodzi mi o dodanie polskich znaków gdyż renderacja obrazków nie odbywa się w języku polskim.

Proszę o pomoc! Big Grin

Odpowiedz
#2
Pokaż kod...
Dobre samopoczucie w tym tygodniu sponsoruje cytat:
Cytat:Mogę tylko tylko na prawo i lewo ale na środek nie mogę.
Odpowiedz
#3
Proszę oto kody Big Grin


index.php
Kod PHP:
<html>
    <
head>
        <
title>Letsgeek motivational poster maker</title>
        <
script language="javascript" type="text/javascript">
            function 
upload_file() {
                
document.getElementById('initial').style.display 'none';
                
document.getElementById('loading').style.display 'inline';
            }
            function 
upload_file_complete(path) {
                
document.getElementById('initial').style.display 'none';
                
document.getElementById('image').src path;
                
document.getElementById('image').style.display 'inline';
                
document.getElementById('result').style.display 'inline';
            }
            function 
changeimage(target) {
                
document.getElementById('exampleimage').src 'images/' target.value '.png';
            }

       </
script>
    </
head>
    <
body>
        <
div id="container" style="width:1024px;">
            <
div>
                <
h1>Create your own motivational poster!</h1>
                <
div style="width:650px;" id="initial">
                    <
form id="upload_form" action="motivational.php" method="post" enctype="multipart/form-data" target="motivational">
                    <
div style="float:left;">
                        <
img src="images/horizontal.png" id="exampleimage">
                    </
div>
                    <
div style="float:right;">
                            <
table>
                                <
tr>
                                    <
td>Upload image:</td><td><input type="file" name="file_upload"></td>
                                </
tr>
                                <
tr>
                                    <
td colspan=2>What format?</td>
                                </
tr>
                                    <
td><input type="radio" name="format" value="horizontal" onclick="changeimage(this)" checked /> Horizontal</td><td><input type="radio" name="format" value="vertical" onclick="changeimage(this)" /> Vertical</td>
                                </
tr>
                                <
tr>
                                    <
td>Title:</td><td><input type="text" name="titletext"></td>
                                </
tr>
                                <
tr>
                                    <
td>Motivational text:</td><td><input type="text" name="motivationaltext"></td>
                                </
tr>
                                <
tr>
                                    <
td>Background color:</td><td><input type="text" name="backgroundcolor" value="000000" size=6 MAXLENGTH=6></td>
                                </
tr>
                                <
tr>
                                    <
td>Text color:</td><td><input type="text" name="textcolor" value="FFFFFF" size=6 MAXLENGTH=6></td>
                                </
tr>
                            </
table>
                            <
input type="hidden" value="1" name="send_upload"/> 
                            <
input type="submit" value="Motivate!">
                        </
div>
                        </
form>
                    </
div>
                <
div style="width:600px;display:none;" id="result">
                    <
img src="images/t.gif" id="image" />
                </
div>
                <
iframe id="motivational" name="motivational" src="" style="width:0;height:0;border:0px solid #fff;">
                </
iframe
            </
div>
        </
div>
    </
body>
</
html

motivational.php

Kod PHP:
<?php

include 'functions.php';

// Variables
$textcolor            $_POST['textcolor'];
$titletext            $_POST['titletext'];
$motivationaltext    $_POST['motivationaltext'];
$backgroundcolor    $_POST['backgroundcolor'];
$format                $_POST['format'];
$allowed_ext        "jpg, gif, png, jpeg, JPG";
$top                50;                                        
$filename            $_FILES['file_upload']['name'];

// Validation
if(!checkRGB($textcolor))
    goto 
SkipToEnd;

if(!
checkRGB($backgroundcolor))
    goto 
SkipToEnd;

/*if(!checkText($titletext))
    goto SkipToEndTwice;

if(!checkText($motivationaltext))
    goto SkipToEndTwice;*/

if($format == 'horizontal'){

        
//Dimensions of the finished image
        
$width 750;
        
$height 650;

        
//Dimensions of the uploaded image
        
$imgx 600;
        
$imgy 450;

    }else{ 
// Vertical

        //Dimensions of the finished image
        
$imgx 600;
        
$imgy 550;

        
//Dimensions of the uploaded image
        
$width 650;
        
$height 750;
    }

// Is the extension allowed?
$extension checkext($filename$allowed_ext);

if (
$extension != False
    {
        
// Move the temporary file to the image folder
        
$save_to="images/";
        if (
$_POST['send_upload']==1
            {
                
$file_name=$_FILES['file_upload']['name'];
                
move_uploaded_file($_FILES['file_upload']['tmp_name'], $save_to.basename($file_name)) or die('Cannot upload image');
                
$filepath $save_to.basename($file_name);
            }

        
// Create an image resource from the uploaded image
        
if($extension == "jpg" || $extension == "jpeg" || $extension == "JPG"){
          
$source=imagecreatefromjpeg($filepath);
        }elseif(
$extension == "png") {
          
$source=imagecreatefrompng($filepath);
        }elseif(
$extension == "gif") {
          
$source=imagecreatefromgif($filepath);
        } 
        
        
// Resize the image resource
        
$width_orig imagesx$source );                                                                    // width of image resource
        
$height_orig imagesy$source );                                                                    // height of image resource
        
$uploadedimage imagecreatetruecolor($imgx$imgy);                                                // Create space for the resized image
        
imagecopyresampled($uploadedimage$source0000$imgx$imgy$width_orig$height_orig);    // Resize the image to the correct dimensions. Outputs to $uploadedimage.

        //Save the resized image
        
if($extension == "jpg" || $extension == "jpeg" || $extension == "JPG"){
            
imagejpeg($uploadedimage$filepath100);
        }elseif(
$extension == "png") {
            
imagepng($uploadedimage$filepath);
        }elseif(
$extension == "gif") {
          
imagegif($uploadedimage$filepath);
        } 

        
// Create the background image
        
$im = @imagecreatetruecolor($width$height) or die('Cannot Initialize new GD image stream');

        
// Allocate colors
        
$textcolor    rgb2array($_POST['textcolor']);
        
$text_color imagecolorallocate($im$textcolor[0], $textcolor[1], $textcolor[2]); 
        
$bordercolors imagecolorallocate($im$textcolor[0], $textcolor[1], $textcolor[2]); 
        
$backgroundcolor rgb2array($backgroundcolor);
        
$backgroundcolor imagecolorallocate($im$backgroundcolor[0], $backgroundcolor[1], $backgroundcolor[2]); 
        
$watermark_color imagecolorallocate($im2331491);

        
// Fill Im with the background color.
        
imagefill ($im00$backgroundcolor);

        
// Draw a border on the background image
        
$size getimagesize($filepath);  
        
$x = ($width 2) - ($size[0] / ) - 2;
        
$y $top 2;
        
$w $imgx 2;
        
$h $imgy 2;
        
imageline($im$x,$y,$x,$y+$h,$bordercolors);
        
imageline($im$x,$y,$x+$w,$y,$bordercolors);
        
imageline($im$x+$w,$y,$x+$w,$y+$h,$bordercolors);
        
imageline($im$x,$y+$h,$x+$w,$y+$h,$bordercolors);

        
// Merge the original image resource with the background image resource
        
imagecopy($im$uploadedimage$x 2$top00$size[0], $size[1]);

        
// Write out the text
        
CenterImageString($im$widthstrtoupper($titletext), 40, ($top $imgy 50), $text_color);
        
CenterImageString($im$width$motivationaltext16, ($top $imgy 74), $text_color);
    
        
// Watermark. Be a sport and dont remove this.
        
ImageString($im2$width-160$height-15"www.letsgeek.com/motivator"$watermark_color);
        
        
//Print and clean stuff
        
imagepng($im"posters/" md5(mktime()) . $filename );
        
imagedestroy($im);
        
imagedestroy($uploadedimage);
        
imagedestroy($source);
    }

$filename "posters/" md5(mktime()) . $filename;
echo 
'
<html>
    <body>
        <script language="javascript" type="text/javascript">
            var path = "'
.$filename.'";
            window.parent.upload_file_complete(path);
        </script>
    <body>
<html>'
;
die();

/* ERROR HANDLING RGB */
SkipToEnd:
echo 
'
<html>
    <body>
        <script language="javascript" type="text/javascript">
            alert("Wrong RGB value");
        </script>
    <body>
<html>'
;
die();

/* ERROR HANDLING TEXT */
SkipToEndTwice:
echo 
'
<html>
    <body>
        <script language="javascript" type="text/javascript">
            alert("'
.$titletext.'");
        </script>
    <body>
<html>'
;
?>

functions.php

Kod PHP:
<?php

//Fix rbg colors
function rgb2array($rgb) {
    
    return array(
        
base_convert(substr($rgb02), 1610),
        
base_convert(substr($rgb22), 1610),
        
base_convert(substr($rgb42), 1610),
    );
}

//Center image
function CenterImageString($image$image_width$string$font_size$y$color)
 {
    
$text_width imagefontwidth($font_size)*strlen($string);
    
$center ceil($image_width 2);
    
$x $center - (ceil($text_width/2));

    
### Get exact dimensions of text string
    
$box = @imageTTFBbox($font_size,0'arial.ttf'$string);
    
### Get width of text from dimensions
    
$textwidth abs($box[4] - $box[0]);
    
### Get x-coordinate of centered text horizontally using length of the image and length of the text
    
$xcord = ($image_width/2)-($textwidth/2)-2;


    
imagettftext($image$font_size0$xcord$y$color'arial.ttf'$string);
 }

function 
checkext($image$allowed_ext)
    {
    
$allowed_ext explode(", "$allowed_ext);
    
$info pathinfo($image); 
    
$extension $info['extension'];
    
$ext False;

    for(
$i 0$i count($allowed_ext); $i++) 
        {    
        if (
$allowed_ext[$i] == $extension) {
          
$ext $allowed_ext[$i]; }
        }
    return 
$ext;
    }

function 
resize($source$imgx$imgy)
    {
        
$width_orig imagesx$source );                                                                    // width of original image
        
$height_orig imagesy$source );                                                                    // height of original image
        
$uploadedimage imagecreatetruecolor($imgx$imgy);                                                // Create space for the resized image
        
imagecopyresampled($uploadedimage$source0000$imgx$imgy$width_orig$height_orig);    // Resize the image to the correct dimensions. Outputs to $uploadedimage.
        
return $uploadedimage;
    }

function 
checkRGB($input) {
    if(
preg_match('/^[a-fA-F0-9]{6}$/'$input)) //Is it valid?
            
Return true;
        Return 
false;
}
?>

uploadscript.php

Kod PHP:
<?php 

//Upload image
$save_to="images";
if (
$_POST['send_upload']==1) {
    
$file_name=$_FILES['file_upload']['name'];
    
move_uploaded_file($_FILES['file_upload']['tmp_name'], $save_to."/".basename($file_name)) or die('FEL');
    
$filepath $save_to."/".basename($file_name);
    }

if(
$_POST['format'] == "horizontal"){
    
$format "horizontal";
    
$width 600;
    
$height 450;
}else{
    
$format "vertical";
    
$width 600;
    
$height 550;
}

?>
<script language="javascript" type="text/javascript">
var path = "<?php echo $filepath?>";
var format = "<?php echo $format?>";
var width = "<?php echo $width?>";
var height = "<?php echo $height?>";
window.top.upload_file_complete();
window.parent.document.getElementById('exampleimage').src = path;
window.parent.document.getElementById('exampleimage').width = width;
window.parent.document.getElementById('exampleimage').height = height;
window.parent.document.getElementById('image').value = path;
window.parent.document.getElementById('format').value = format;
</script>'; 


Odpowiedz
#4
1. Kodowanie plików.
2. Odpowiedni charset na stronie (oba utf-8).

Zrób ten przykład i powiedz co Ci pluje?

Kod:
<?php
header("Content-type: image/png");

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'ęółąśżźćńć ĘÓŁĄŚŻŹĆŃ';
// Replace path by your own font path
$font = 'arial.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
Dobre samopoczucie w tym tygodniu sponsoruje cytat:
Cytat:Mogę tylko tylko na prawo i lewo ale na środek nie mogę.
Odpowiedz
#5
Tu masz

http://irzykpol.cba.pl/blad.png
Tu masz przykład a zresztą na stronie http://irzykpol.cba.pl masz dowód. Gdy chcesz wy-renderować w text i 2 text to wychodzi ci coś takiego

http://irzykpol.cba.pl/posters/83991958cc8d88d77d042e5705ae32a4z_cyklu_pieskie_zycie17.jpg
jak chce ąą i ćć i żżż i wszystkie polskie znaki :/
Odpowiedz
#6
możliwe, że w bazie danych masz skopane kodowanie i dlatego wyświetla takie krzaki. Zrobiłeś kodowanie tak jak Pedro84 pisał ?
Odpowiedz
#7
Czyli musze w MySQL zmienić kodowanie na standardowe UTF 8?
Ale to się nie dodaje do bazy to stwarza obrazek i dodaje do folderu poster. Potem będę kodował żeby dodawał do bazy i tytuł tylko nie wiem jak z tymi polskimi znakami:/
Odpowiedz
#8
Nie, po co w bazie? Ten skrypt w ogóle się z nią łączy? Zapisz w UTF8 w jakimś lepszym notatniku, np. Notepad++
Odpowiedz
#9
spróbuje
Odpowiedz
#10
w sumie nie popatrzyłem w kod tylko w ciemno stwierdziłem, że jest baza Smile mój błąd. No to tylko kodowanie plików UTF-8
Odpowiedz


Podobne wątki…
Wątek: Autor Odpowiedzi: Wyświetleń: Ostatni post
  Skrypt sklepu zintegrowany z własnym layoutem/stroną HTML. damianusix 3 5,077 05-07-2021, 05:47
Ostatni post: MrOMGWTF
  Skrypt do poczty od wielu dostawców glassini 0 1,552 17-05-2017, 17:56
Ostatni post: glassini
  Skrypt pytań i odpowiedzi SanKylo 0 2,754 29-04-2015, 23:28
Ostatni post: SanKylo
  Czy skrypt jest potrzebny do tv xtronix856 2 3,999 23-05-2012, 02:51
Ostatni post: xtronix856
  Darmowy skrypt IPB, vB. weboker 6 8,409 30-11-2011, 01:22
Ostatni post: teken

Skocz do:


Użytkownicy przeglądający ten wątek: 1 gości
Sponsorzy i przyjaciele
SeoHost.pl