Jump to content

Creating images from gifs, jpegs. pngs


altemur

Recommended Posts

I have created colourfull images of characters of letters.

 

by using a form i want to create words. the words will be a image.

 

For exemple "word" is 4 letter. İnstead of 4 diffeen picture. Only one picture.

i have tried with createimagefromgif function php but i couldnt.

 

How we can do that?

Thank for advance

Link to comment
https://forums.phpfreaks.com/topic/41885-creating-images-from-gifs-jpegs-pngs/
Share on other sites

Make sure PHP is compiled with GD support.  Just search google for articles containing how you would enable GD support on a PHP based server.

 

Then, you'd need to look into imagecreatefrompng or such other functions.  Also, you'll need to read up on imagettftext or imagestring, as well was imagepng/imagejpeg/imagegif...etc.

$len = strlen(strval($count));
if($len > $min_width) $width = $len;
else $width = $min_width;

if(!file_exists("$digit_dir/0.jpg")){
  die("No images in digit-dir");
}

$d0 = ImageCreateFromjpeg("$digit_dir/0.jpg");
$dx = ImageSX($d0);
$dy = ImageSY($d0);


$img = ImageCreateTrueColor($width*$dx, $dy);

ImageDestroy($d0);

$xoff = $width*$dx;
while($xoff > 0) {
  $digit = $count % 10;
  $count = $count / 10;
  $temp = ImageCreateFromjpeg("$digit_dir/$digit.jpg");
  $xoff = $xoff - $dx;
  ImageCopyResized($img,  $temp,  $xoff, 0,  0,  0,  $dx,  $dy,  $dx,  $dy);
  ImageDestroy($temp);
    }

Header("Content-type: image/jpg");

Imagejpeg($img);
ImageDestroy($img); 

Sorry i for get to put all codes.

Here all the page

 

<?php

/********************************************************
Variables
*********************************************************/

$digit_dir = "./digits";
$file = "counter.txt";
$min_width = 5;
$lifetime = 30;
$domain = "www.offsite.be";

$use_mail = 1;
$trigger = 1000;
$your_email = "[email protected]";


/********************************************************
Code --> DO NOT EDIT BELOW THIS POINT
*********************************************************/

$fp = fopen($file, "r") or die("Failed to open counter-file");
$size = filesize($file);
$count = fread($fp, $size);
fclose($fp);

if(!Isset($_COOKIE['counter'])){
  $fp = fopen($file, "w");
$count++;
fwrite($fp, $count);
fclose($fp);
  setcookie("counter","dummy",time()+60*60*24*$lifetime,$domain);
  
  if($use_mail AND ($count%$trigger==0)){
    $headers = "From: Counter <noreply@$domain>\n";
    $headers .= "X-Sender: <noreply@$domain>\n";
    $headers .= "X-Mailer: Offsite Counterscript\n";
    $headers .= "Return-Path: <noreply@$domain>\n";
    $subject = "Counter information from $domain";
    $message = "Congratulations!\n\nThe number of visitors on your site has reached $count.";
    mail($email,$subject,$message,$headers);
  }
}

$len = strlen(strval($count));
if($len > $min_width) $width = $len;
else $width = $min_width;

if(!file_exists("$digit_dir/0.jpg")){
  die("No images in digit-dir");
}

$d0 = ImageCreateFromjpeg("$digit_dir/0.jpg");
$dx = ImageSX($d0);
$dy = ImageSY($d0);


$img = ImageCreate($width*$dx, $dy);

ImageDestroy($d0);

$xoff = $width*$dx;
while($xoff > 0) {
  $digit = $count % 10;
  $count = $count / 10;
  $temp = ImageCreateFromjpeg("$digit_dir/$digit.jpg");
  $xoff = $xoff - $dx;
  ImageCopyResized($img,  $temp,  $xoff, 0,  0,  0,  $dx,  $dy,  $dx,  $dy);


  ImageDestroy($temp);
    }

Header("Content-type: image/jpg");

Imagejpeg($img);

ImageDestroy($img); 

?> 

is there an actual image0.jpg...whats in it?  I cant se where you set the background colour.  havent time to test...but those are the 2 things i'd check.

 

Will

 

the images in

 

$digit_dir = "./digits";

 

and i do not know where i can set the background color

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.