bagder: curl-www/libcurl/php/examples mkindex.pl, 1.3, 1.4 resizejpg.php, NONE, 1.1 resizejpg.php.html, NONE, 1.1

[email protected]
Newsgroups gmane.comp.web.curl.www.cvs
Message-ID <[email protected]>
Update of /cvsroot/curl/curl-www/libcurl/php/examples
In directory labb:/tmp/cvs-serv6279

Modified Files:
	mkindex.pl 
Added Files:
	resizejpg.php resizejpg.php.html 
Log Message:
Michael Phipps' resizejpg example, added with permission. And modified the
top-example description to be HTML and not <pre>


Index: mkindex.pl
===================================================================
RCS file: /cvsroot/curl/curl-www/libcurl/php/examples/mkindex.pl,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- mkindex.pl	4 Nov 2005 23:38:48 -0000	1.3
+++ mkindex.pl	9 Nov 2005 09:00:09 -0000	1.4
@@ -81,7 +81,7 @@
     subtitle("The $ex Example");
 
     if( -r "$ex.html") {
-        precatfile("$ex.html");
+        catfile("$ex.html");
     }
 
     precatfile($ex);

--- NEW FILE: resizejpg.php.html ---
Download a remote image, resize it and show it to the user. Written by <a title="Michael Phipps is a PHP Programmer located in Brisbane, Queensland, Australia." href="http://michaelphipps.com" >Michael Phipps</a>

--- NEW FILE: resizejpg.php ---
/*
  you can use it in your webpage like this:
  <img src=resizejpg.php?size=60&filename=http://anydomain.com/anyimage.jpg>

  Hope the code helps you! / Michael

*/

<?php
function LoadJpeg ($imgname) {
$im = @ImageCreateFromJPEG ($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 $imgname", $tc);
}
  return $im;
}

$id=$filename;
$sz=$size;
$savefile="tempimg/".time().".jpg";

$ch = curl_init ($id);
$fp = fopen ($savefile, "w");
curl_setopt ($ch, CURLOPT_FILE, $fp);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_exec ($ch);
curl_close ($ch);
fclose ($fp);

$im=LoadJpeg($savefile);

// output
$im_width=imageSX($im);
$im_height=imageSY($im);

// work out new sizes
if($im_width >= $im_height)
{
  $factor = $sz/$im_width;
  $new_width = $sz;
  $new_height = $im_height * $factor;
}
else
{
  $factor = $sz/$im_height;
  $new_height = $sz;
  $new_width = $im_width * $factor;
}

// resize
$new_im=ImageCreate($new_width,$new_height);
ImageCopyResized($new_im,$im,0,0,0,0,
                 $new_width,$new_height,$im_width,$im_height);

// output
Header("Content-type: image/jpeg");
header( "Content-Disposition:attachment;filename=$filename" );
header( "Content-Description:PHP Generated Image" );
Imagejpeg($new_im,'',75); // quality 75

// cleanup
ImageDestroy($im);
ImageDestroy($new_im);
unlink($savefile);
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.