When I try to use absolute/url paths with [man]imagecreatefrompng[/man], it doesn't work. The file just times out. What could be causing this? I don't get an error or anything. It works fine with relative paths.

Is there a setting I need to change? I am building the website on my local machine, using Appserv, a windows based program that runs MYSQL and Apache. The absolute path I am using is http://localhost/.

    I just tried this script (just added some stuff to the script from php.net), and it worked fine on my machine.

    <?php
    
    function LoadPNG($imgname)
    {
       global $im;
    
       $im = @imagecreatefrompng($imgname); /* Attempt to open */
       if (!$im) { /* See if it failed */
           $im  = imagecreate(150, 30); /* Create a blank image */
           $bgc = imagecolorallocate($im, 255, 255, 255);
           $tc  = imagecolorallocate($im, 0, 0, 0);
           imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
           /* Output an errmsg */
           imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
       }
       return $im;
    }
    
    LoadPNG('http://localhost:7628/projects/image_png/pnglogo-blk-sml1.png');
    
    imagepng($im, "woo.png");
    
    ?>

    Show me the script you're using and maybe I can help you. This script also worked when I used:

    LoadPNG('http://www.libpng.org/pub/png/img_png/pnglogo-blk-sml1.png');
    

    But, I guess if you show me what you're working with maybe I can identify the problem. Hope I can help. 🙂

      Yeah, show us some code. But, if it's URL's you're opening, might want to check the 'allow_url_fopen' directive. Is it allowed?

        Why would you need to use an absolute URL to localhost? If the image is on localhost then surely you can just locate the file by its file path?

          I want to use absolute paths to have it be more secure. I could use file:///, but some things don't like that beginning, so I use http://localhost/. Also, I plan on moving my site to another host, and plan to use absolute paths when I do so.

          My PHP.ini says:

          allow_url_fopen = On

          Here's some code: Sorry it's not organized visually right now...

          <?php
          
          include 'functions.php';
          include 'config.php';
          include 'connect.php';
          include 'sessions.php';
          
          $abs_path = 'http://localhost/spcatv/';
          $path_to_images = $abs_path.'images/';
          $path_to_templates = $path_to_images.'templates/';
          
          $image_type = array (
          1 => 'navi',
          2 => 'large',
          3 => 'small',
          );
          If (!$_SESSION['image_fields'])
          {
          $result=get_image_fields();
          If (!$result)
          {
          $error = 'There is an error in the image fields array';
          reg_error($error);
          }
          }
          If ($_SESSION['submitted'])
          {
          For ($z = 1; $z <= sizeof($image_type); $z++)
          {
          $type = $choice_type[$_SESSION['x']].'_'.$image_type[$z];
          
          Switch ($type) //Selects the type, I know it's redundant, but I want it to adapt to anything...
          {
          //--------------[NAVIGATION]------------------------------------
          case "navi":
          $imagesource =  $abs_path.$path_to_templates."navi.png";
          $startwidth = (30);
          $fontsize=11;
          $path_to_store = $path_to_images.$choice_type[$_SESSION['x']].'/generated/';
          break;
          
          
          case "crew_navi":
          $imagesource =  $abs_path.$path_to_templates."navi.png";
          $startwidth = (50);
          $fontsize=10;
          $path_to_store = $path_to_images.'navi/generated/';
          break;
          
          case "evnt_navi":
          $imagesource =  $abs_path.$path_to_templates."navi.png";
          $startwidth = (50);
          $fontsize=10;
          $path_to_store = $path_to_images.'navi/generated/';
          break;
          
          case "news_navi":
          $imagesource =  $abs_path.$path_to_templates."navi.png";
          $startwidth = (50);
          $fontsize=10;
          $path_to_store = $path_to_images.'navi/generated/';
          break;
          
          //--------------[DEFAULT]---------------------------------------
          
          default:
          $error = "You have gotten to this page worngly!  Please follow the correct urls!";;
          disaster_error($error);
          break;
          }
          
          $filetype = substr($imagesource,strlen($imagesource)-4,4);
          
          $filetype = strtolower($filetype);
          
          Switch ($filetype)
          {
          case '.gif':
          $image = @imagecreatefromgif($imagesource);
          break;
          
          case '.jpg':
          $image = @imagecreatefromjpeg($imagesource);
          break;
          
          case '.png':
          $image = @imagecreatefrompng($imagesource);
          break;
          }
          if (!$image) die('errpr');
          
          $font = '../images/fonts/tahoma.ttf';
          
          $imagewidth = imagesx($image);
          
          $imageheight = imagesy($image);
          
          $fontwidth = imagefontwidth($font);
          
          $fontheight = imagefontheight($font);
          
          $string=$_SESSION['name']; //Add Abbrevation!!!!
          
          $startheight = (($imageheight + $fontheight)/2);
          
          $white = imagecolorallocate($image, 255, 255, 255);
          
          $black = ImageColorAllocate($image, 0, 0, 0);
          
          imagettftext($image, $fontsize, 0, $startwidth, $startheight, $white, $font, $string);
          
          imagepng($image, $path_to_store.$_SESSION['id'].'_'.$image_type[$z].".png");
          
          imagedestroy($image);
                           print ($path_to_store);
          If ($_SESSION['method'] == 'create')
          {
          $query = 'Insert into '.$image_table_name.' Values (\'\',\''.$_SESSION['id'].'\',\''.$image_type[$z].'\')';
          mysql_close();
          }
          }
          }
          If (!$error)
          {
          $_SESSION['image_done'] = 'set';
          $to = 'process.php?sid='.session_id();
          redirect($to);
          }
          Else
          {
          Print ('Error'.$error_codes[$error]);
          die();
          }
          ?>
            Write a Reply...