Hello Guys ,
I want to create a script that convert a text file or Nfo file to an image(format is .PNG).
What it does is simply load the txt and output it as an image
Here is my code:
<?php
if(isset($_FILES['image'])){
$errors = array();
$allowed_ext = array('txt');
$file_name = $_FILES['image']['name'];
$file_ext = strtolower(end(explode('.', $file_name)));
$path = $_SERVER['DOCUMENT_ROOT'].'/fileupload'.'/images/';
if(in_array($file_ext, $allowed_ext) ===false){
$errors [] = 'Extension not allowed.';
}
if ($file_ext =='txt') {
$font_file = "C:/WINDOWS/Fonts/cour.ttf";
$nfo_file_lines = file($file_name);
$width = 0;
for($i = 0; $i < count($nfo_file_lines); $i++) {
$box = imagettfbbox($file_size, 0, $font_file, $nfo_file_lines[$i]);
$width = max($width, $box[2]);
}
$image = imagecreate($width, $file_size * (count($nfo_file_lines) + 1));
$background_color = imagecolorallocate($image, 0, 0, 0);
$text_color = imagecolorallocate($image, 255, 255, 255);
for($i = 0; $i < count($nfo_file_lines); $i++) {
imagettftext($image, $file_size, 0, 0, $file_size * ($i + 1), $text_color, $font_file, $nfo_file_lines[$i]);
}
imagepng($image); //show image
imagepng($image,$path); //saves generated png in $path
imagedestroy($image); //des
}
}
else{
foreach($errors as $error){
echo 'Contact WebMaster as only he can fix:D', '<br />';
}
}
?>
However i am getting there errors , please help me out
Warning: file(1337day.txt) [function.file]: failed to open stream: No such file or directory in E:\AppServ\www\fileupload\test\upload.php on line 14
Warning: imagecreate() [function.imagecreate]: Invalid image dimensions in E:\AppServ\www\fileupload\test\upload.php on line 20
Warning: imagecolorallocate(): supplied argument is not a valid Image resource in E:\AppServ\www\fileupload\test\upload.php on line 21
Warning: imagecolorallocate(): supplied argument is not a valid Image resource in E:\AppServ\www\fileupload\test\upload.php on line 22
Warning: imagettftext() expects parameter 1 to be resource, boolean given in E:\AppServ\www\fileupload\test\upload.php on line 24
Warning: imagepng(): supplied argument is not a valid Image resource in E:\AppServ\www\fileupload\test\upload.php on line 26
Warning: imagepng(): supplied argument is not a valid Image resource in E:\AppServ\www\fileupload\test\upload.php on line 27
Warning: imagedestroy(): supplied argument is not a valid Image resource in E:\AppServ\www\fileupload\test\upload.php on line 28
Thanks a ton guys