/    Sign up×
Community /Pin to ProfileBookmark

PHP ImageCreate problem

Hi everyone and body.

I am facing a problem wit ImageCreate. I wish to dispaly var values that are in an other php file. But as soon as I use: include_once(‘xxxx.php’);

The image does not create anymore. Help to be able to import data will be appreciated.

[QUOTE]

<?php

//include_once(‘live/testtags.php’);
// If included script will not work…. ????

create_image();
exit();

function create_image() {

//Let’s generate a totally random string using md5
$md5 = md5(rand(0,999));
//We don’t need a 32 character long string so we trim it down to 10
$pass = substr($md5, 0, 10);

//Set the image width and height
$width = 500;
$height = 40;

//Create the image resource
$image = ImageCreate($width, $height);

$string = “MyString”;

//We are making three colors, white, black and gray
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$grey = ImageColorAllocate($image, 204, 204, 204);
$green = ImageColorAllocate($image, 0, 192, 0);
//Make the background black

// ImageFill($image, 0, 0, $grey);
$image = imagecreatefromjpeg(“myjpg_pict.jpg”);
//Add randomly generated string in white to the image
ImageString($image, 3, 30, 3, $pass, $white);

imagestring ( $image , 5, 20 , 20 , $string , $green );

//Throw in some lines to make it a little bit harder for any bots to break
ImageRectangle($image,0,0,$width-1,$height-1,$grey);
imageline($image, 0, $height/2, $width, $height/2, $grey);
imageline($image, $width/2, 0, $width/2, $height, $grey);

header(“Content-Type: image/jpeg”);

//Output the newly created image in jpeg format
ImageJpeg($image); // ImageJpeg($image’./myimage.jpg’);

//Free up resources
ImageDestroy($image);

}
?>

[/QUOTE]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@iBeZiApr 27.2015 — 
  • 1. Does the file exist?

  • 2. Are there any errors in the file you're including?

  • 3. Have you checked your error logs?
  • Copy linkTweet thisAlerts:
    @gdlmusauthorApr 27.2015 — 1. Does the file exist?

    2. Are there any errors in the file you're including?

    3. Have you checked your error logs?[/QUOTE]

    :rolleyes:

    Well thanks so lot for your constructive suggestions.

    Allow me now to suggest you to try it yourself. Just copy an paste the PHP script and create a PHP file. Run it thru wamp or any local server and see by yourself. It will work fine. Now uncomment the include_once('myothrtphpfilr.php'); In that new ceated other PHP file just put between the <?php ?> tags $foo='foo'; and retest... Will not work... !!!?

    I love your questions... From now on I will verify that I have food on my fork before bringing it to my mouth. ?

    Thanks for the help? Good evening.

    Regards.

    -= Guy =-
    Copy linkTweet thisAlerts:
    @NogDogApr 27.2015 — Make sure that the included file does not output [i]anything[/i], including anything before or after the PHP tags -- even newlines, the dreaded BOM if saved as UTF-8 with BOM, and so forth. (In fact, it's always a good idea to leave the closing "?>" tag off of any include PHP files, since it's optional anyway. If you cannot prevent output, you could try something like:
    [code=php]
    ob_start();
    include 'whatever/you/want';
    ob_end_clean();
    [/code]
    Copy linkTweet thisAlerts:
    @gdlmusauthorApr 28.2015 — Make sure that the included file does not output [i]anything[/i], including anything before or after the PHP tags -- even newlines, the dreaded BOM if saved as UTF-8 with BOM, and so forth. (In fact, it's always a good idea to leave the closing "?>" tag off of any include PHP files, since it's optional anyway. If you cannot prevent output, you could try something like:
    [code=php]
    ob_start();
    include 'whatever/you/want';
    ob_end_clean();
    [/code]
    [/QUOTE]


    Well Thanks so lot NogDog, I believed I had already thanked you but it seems that the post did not go thru.

    Any way, your help reminded me that I stupidly had forgotten the ob_xxx functions.

    It is now working, but still facing a weird pb.

    If I leave my calling main script in the root and call the include that is in

    a child folder (ex: include_once('mysubfolder2/myincludedscipt.php'); ) every thing

    works fine.

    Now let's move the same calling main script in an other sub folder it becomes

    root/mysubfolder1/mymainscript.php in that script I then have to modify the path

    to the included script:

    include_once('../mysubfolder2/myincludedscipt.php');

    I tested the file is found but not included. And the script no longer works.

    Any clue...?

    Thanks for the helpS

    Regards.

    -= Guy =-
    Copy linkTweet thisAlerts:
    @gdlmusauthorApr 28.2015 — Well Thanks so much again NogDog.

    I found my weird stupid mistake.

    I was not calling correct path to fonts to be loaded for imagecreate.

    Back in business now.

    Best regards.

    -= Guy =-
    ×

    Success!

    Help @gdlmus spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 4.29,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...