note 5851 modified in function.imagecreatefromgif by felipe

From: Date: Mon, 26 May 2008 19:48:45 +0000
Subject: note 5851 modified in function.imagecreatefromgif by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-139812@lists.php.net to get a copy of this message
<?php function myImageCreateFromGif($file_or_url) { $dummy_file = "/tmp/dummy.gif"; # if this is a url, use fopen to get the file data, then # save it to a dummy file if (preg_match("/(http|ftp):\/\//i", $file_or_url)) { # open the file using fopen, which supports remote URLs $input = fopen($file_or_url, "rb"); # read the contents of the file # will accept files up to 10Mb, but will probably get # and EOF before that, we have to do it this way because # filesize isn't designed to work with URLs. sigh. $image_data = fread($input, 10000000); fclose($input); # write the contents to a dummy file $output = fopen("$dummy_file", "wb"); fwrite($output, $image_data); fclose($output); # create the gif from the dummy file $image = ImageCreateFromGif($dummy_file); # get rid of the dummy file unlink($dummy_file); } # if it's not a URL, we can simply open the image directly else { $image = ImageCreateFromGif($file_or_url); } if ($image) { return $image; } else { return 0; } } if (!$url) { $url = "http://scholar.lib.vt.edu/images/cornholio.gif";} $image = myImageCreateFromGif($url); if ($image == "" || $image == 0) { print "<p>No Image data was returned...</p>\n"; } else { header("Content-Type: image/gif\n\n"); ImageGif($image); } ?> --was-- <pre> function myImageCreateFromGif($file_or_url) { $dummy_file = "/tmp/dummy.gif"; # if this is a url, use fopen to get the file data, then # save it to a dummy file if (preg_match("/(http|ftp):\/\//i", $file_or_url)) { # open the file using fopen, which supports remote URLs $input = fopen($file_or_url, "rb"); # read the contents of the file # will accept files up to 10Mb, but will probably get # and EOF before that, we have to do it this way because # filesize isn't designed to work with URLs. sigh. $image_data = fread($input, 10000000); fclose($input); # write the contents to a dummy file $output = fopen("$dummy_file", "wb"); fwrite($output, $image_data); fclose($output); # create the gif from the dummy file $image = ImageCreateFromGif($dummy_file); # get rid of the dummy file unlink($dummy_file); } # if it's not a URL, we can simply open the image directly else { $image = ImageCreateFromGif($file_or_url); } if ($image) { return $image; } else { return 0; } } if (!$url) { $url = "http://scholar.lib.vt.edu/images/cornholio.gif";} $image = myImageCreateFromGif($url); if ($image == "" || $image == 0) { print "<p>No Image data was returned...</p>\n"; } else { header("Content-Type: image/gif\n\n"); ImageGif($image); } ?> </pre> http://php.net/manual/en/function.imagecreatefromgif.php

« previous php.notes (#139812) next »