Author Topic: imagejpeg outputs url  (Read 217 times)

0 Members and 1 Guest are viewing this topic.

Offline stuffradioTopic starter

  • Enthusiast
    • View Profile
imagejpeg outputs url
« on: July 04, 2009, 01:08:01 AM »
I'm not sure if it is the fault of imagejpeg though.

This is my upload code:

Code: [Select]
<?php
define
('MAX_FILE_SIZE'9000);
require_once(
"TextToImage.class.php");
$img = new TextToImage();

$target_path $_SERVER['DOCUMENT_ROOT']."wordpress2-8/wp-content/uploads/";
$topx $_POST['xtopalignment'];

$title $_POST['titletext'];

$target_path $target_path basename$_FILES['file']['name']);
$img->im $_FILES['file']['name'];

if(
move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
    echo 
"The file ".  basename$_FILES['file']['name']). 
    
" has been uploaded";
echo "Upload: " $_FILES["file"]["name"] . "<br />";
    echo 
"Type: " $_FILES["file"]["type"] . "<br />";
    echo 
"Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo 
"Temp file: " $_FILES["file"]["tmp_name"] . "<br />";
//echo "Image: <img src=imagedisplay.php?text=" . $_POST[titletext] ."&file=".$_FILES["file"]["name"]. "&x=" . $topx . "&y=" . $topy ." border=0 />";
echo $img->imagettfJustifytext($title"arial.ttf"$topx);
print_r($img->showAsJpg());
imagedestroy($target_path);
} else{
    echo 
"There was an error uploading the file, please try again!";
}

?>

This is the image creation code:

Code: [Select]
<?php
/**
 * Class for converting Text to Image.
 * Left Right Center align/justify of text in image.
 * Create an image from text and align them as you want.
 * @author Taslim Mazumder Sohel
 * @deprecated 1.0 - 2007/07/25
 * 
 */
 
class TextToImage {

var $im;
    private 
$L_R_C;
    
    
/**
     * @name     : makeImageF
     * 
     * Function for create image from text with selected font.
     * 
     * @param String $text     : String to convert into the Image.
     * @param String $font     : Font name of the text. Kip font file in same folder.
     * @param int    $W        : Width of the Image.
     * @param int    $H        : Hight of the Image.
     * @param int  $X        : x-coordinate of the text into the image.
     * @param int    $Y        : y-coordinate of the text into the image.
     * @param int    $fsize    : Font size of text.
     * @param array  $color    : RGB color array for text color.
     * @param array  $bgcolor  : RGB color array for background.
     * 
     */
    
public function imagettfJustifytext($text$font="CENTURY.TTF"$Justify=2$W=0$H=0$X=0$Y=0$fsize=12$color=array(0x0,0x0,0x0), $bgcolor=array(0xFF,0xFF,0xFF)){
    

    
$angle 0;
    
$this->L_R_C $Justify
    
$_bx imageTTFBbox($fsize,0,$font,$text);

$W = ($W==0)?abs($_bx[2]-$_bx[0]):$W; //If Height not initialized by programmer then it will detect and assign perfect height. 
$H = ($H==0)?abs($_bx[5]-$_bx[3]):$H; //If Width not initialized by programmer then it will detect and assign perfect width. 

    
$this->im = @imagecreate($W$H)
    or die("Cannot Initialize new GD image stream");
    
    
$background_color imagecolorallocate($this->im$bgcolor[0], $bgcolor[1], $bgcolor[2]); //RGB color background.
$text_color imagecolorallocate($this->im$color[0], $color[1], $color[2]); //RGB color text.

if($this->L_R_C == 0){ //Justify Left

imagettftext($this->im$fsize$angle$X$fsize$text_color$font$text);

}elseif($this->L_R_C == 1){ //Justify Right
$s split("[\n]+"$text);
    
$__H=0;
    

    
foreach($s as $key=>$val){
    

    
$_b imageTTFBbox($fsize,0,$font,$val);
    
$_W abs($_b[2]-$_b[0]); 
    
//Defining the X coordinate.
    
$_X $W-$_W;
//Defining the Y coordinate.
$_H abs($_b[5]-$_b[3]);  
$__H += $_H;  
    
imagettftext($this->im$fsize$angle$_X$__H$text_color$font$val);
    
$__H += 6;
    

    
}
    

}
elseif($this->L_R_C == 2){ //Justify Center
    

    
$s split("[\n]+"$text);
    
$__H=0;
    

    
foreach($s as $key=>$val){
    

    
$_b imageTTFBbox($fsize,0,$font,$val);
    
$_W abs($_b[2]-$_b[0]); 
    
//Defining the X coordinate.
    
$_X abs($W/2)-abs($_W/2);
//Defining the Y coordinate.
$_H abs($_b[5]-$_b[3]);  
$__H += $_H;  
    
imagettftext($this->im$fsize$angle$_X$__H$text_color$font$val);
    
$__H += 6;
    

    
}
    

    
}

    }
    

    
/**
     * @name showAsPng
     * 
     * Function to show text as Png image.
     *  
     */ 
    
public function showAsPng(){

header("Content-type: image/png");
return imagepng($this->im);
}
    
    
/**
     * @name saveAsPng
     * 
     * Function to save text as Png image.
     *  
     * @param String $filename  : File name to save as.
     * @param String $location  : Location to save image file.
     */ 
    
public function saveAsPng($fileName$locationnull){

$_fileName $fileName.".png";
$_fileName is_null($location)?$_fileName:$location.$_fileName;
return imagepng($this->im$_fileName);
}
    
    
/**
     * @name showAsJpg
     * 
     * Function to show text as JPG image.
     *  
     */ 
    
public function showAsJpg(){

header("Content-type: image/jpeg");
return imagejpeg($this->im);
}
    
    
/**
     * @name saveAsJpg
     * 
     * Function to save text as JPG image.
     *   
     * @param String $filename  : File name to save as.
     * @param String $location  : Location to save image file.
     */ 
    
public function saveAsJpg($fileName$locationnull){

$_fileName $fileName.".jpg";
$_fileName is_null($location)?$_fileName:$location.$_fileName;
return imagejpeg($this->im$_fileName);
}

/**
     * @name showAsGif
     * 
     * Function to show text as GIF image.
     *  
     */ 
public function showAsGif(){

header("Content-type: image/gif");
return imagegif($this->im);
}
    
    
/**
     * @name saveAsGif
     * 
     * Function to save text as GIF image.
     *   
     * @param String $filename  : File name to save as.
     * @param String $location  : Location to save image file.
     */ 
    
public function saveAsGif($fileName$locationnull){

$_fileName $fileName.".gif";
$_fileName is_null($location)?$_fileName:$location.$_fileName;
return imagegif($this->im$_fileName);
}

}
?>


I don't expect you to go through the image creation class, but I am trying to use showAsJpg() and the imagettfJustifytext() function because it has the alignment built in to it.

The problem is, whatever is going on (the uploading of a file works) but it always outputs
Quote
http://localhost/wordpress2-8/wp-content/plugins/captionbuilder/uploader.php


and I'm not sure why.

Offline stuffradioTopic starter

  • Enthusiast
    • View Profile
Re: imagejpeg outputs url
« Reply #1 on: July 04, 2009, 01:30:16 AM »
I commented out this line

Code: [Select]
$img->showAsJpg();

and it shows text output, but that means I'm still stuck on why it doesn't output any images.

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.