Author Topic: Carter Lake image resizer  (Read 1183 times)

0 Members and 1 Guest are viewing this topic.

Offline tmabell

  • Forecaster
  • *****
  • Posts: 394
    • Mishawaka Weather
Carter Lake image resizer
« on: June 09, 2014, 01:57:33 PM »
Is there a way to make the "Radar Down" font larger by making a change in this script?

<?php
// Create Thumbnail and a new output of radar image
// I've found for code to work, you need to have a graphic
// of the output file name on your server and CHMOD 666
// This also crops the DBZ off the edge so you have to make
// Your input file 562 pixels wide and it crops down to 512

// Shut off error reporting so we don't get any errors displaying for visitors
error_reporting(0);

if ( empty($_REQUEST['force']) )
        $_REQUEST['force']="0";

$Force = $_REQUEST['force'];


//
$my_input_file = $_SERVER['DOCUMENT_ROOT'] . '/radar/koax_br248.jpg';
$my_output_file2 = $_SERVER['DOCUMENT_ROOT'] . '/radar/koax_br248c.jpg';
$my_output_file = $_SERVER['DOCUMENT_ROOT'] . '/radar/miniradar.jpg';

if (filesize($my_input_file) > 40000) {

$mytime = time();

   // set output jpeg quality
   $jpeg_quality = 90;

   // set thumbnail height to use
   $thumb_height = 120;

   // set thumbnail width to use
   $thumb_width = 120;

   // $size[0] = the width of input image : $size[1] = the height of input image
   $size = getimagesize($my_input_file);

   $cropStartX = 50;
   $cropStartY = 0;
   $cropW  = 512;
   $cropH  = 512;
   $quality = 90;

// Cache the image until there's a new original to make a thumbnail of
// This greatly reduces server load and page load time.
if (filemtime($my_input_file) > filemtime($my_output_file)) {

   if ($size[0]==562) {

      sleep (1);

      // Create two images
      $origimg = imagecreatefromjpeg($my_input_file);
      $cropimg = imagecreatetruecolor($cropW,$cropH);

      // Crop
      imagecopyresized($cropimg, $origimg, 0, 0, $cropStartX, $cropStartY, $size[0], $size[1], $size[0], $size[1]);

      $white = imagecolorallocate ($cropimg, 255,255,255);
      putenv('TZ=US/Central');
      $imagetime = date("g:i A");
      imagestring($cropimg,FF_ARIAL,470,503,$imagetime,$white);

      imagejpeg($cropimg,$my_output_file2,$quality);

      // destroy the images
      imagedestroy($cropimg);
      imagedestroy($origimg);
   }

   $size = getimagesize($my_output_file2);

   // create image in memory
   $src_img = imagecreatefromjpeg($my_output_file2);
   $dst_img = imagecreatetruecolor($thumb_width,$thumb_height);
   imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_width, $thumb_height, $size[0], $size[1]);

   // write output image
   imagejpeg($dst_img, $my_output_file, $jpeg_quality);

   // free memory used
   imagedestroy($src_img);
   imagedestroy($dst_img);

} else if (filemtime($my_input_file) < $mytime - 1500) {

   $size = getimagesize($my_output_file2);

   sleep (1);

   // create image in memory
   $org_img = imagecreatefromjpeg($my_input_file);
   $src_img = imagecreatefromjpeg($my_output_file2);
   $dst_img = imagecreatetruecolor($thumb_width,$thumb_height);
   imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_width, $thumb_height, $size[0], $size[1]);

   // If radar image is over 20 minutes old, add text that radar is down
   $white = imagecolorallocate ($dst_img, 255,255,255);
   imagestring($dst_img,2,20,50,"RADAR DOWN",$white);
   imagestring($src_img,2,230,280,"RADAR DOWN",$white);

   $Notupdated = "RADAR HAS NOT UPDATED IN LAST 25+ MINUTES";

   imagestring($src_img,2,100,380,$Notupdated,$white);

   // write output image
   imagejpeg($dst_img, $my_output_file, $jpeg_quality);
   imagejpeg($org_img, $my_input_file, 100);
   imagejpeg($src_img, $my_output_file2, 100);

   // free memory used
   imagedestroy($org_img);
   imagedestroy($src_img);
   imagedestroy($dst_img);

} else if ($Force==1) {

   if ($size[0]==562) {

      sleep (2);

      // Create two images
      $origimg = imagecreatefromjpeg($my_input_file);
      $cropimg = imagecreatetruecolor($cropW,$cropH);

      // Crop
      imagecopyresized($cropimg, $origimg, 0, 0, $cropStartX, $cropStartY, $size[0], $size[1], $size[0], $size[1]);

      $white = imagecolorallocate ($cropimg, 255,255,255);
      putenv('TZ=US/Central');
      $imagetime = date("g:i A");
      imagestring($cropimg,FF_ARIAL,470,503,$imagetime,$white);

      imagejpeg($cropimg,$my_output_file2,$quality);

      // destroy the images
      imagedestroy($cropimg);
      imagedestroy($origimg);
   }

   $size = getimagesize($my_output_file2);

   // create image in memory
   $src_img = imagecreatefromjpeg($my_output_file2);
   $dst_img = imagecreatetruecolor($thumb_width,$thumb_height);
   imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_width, $thumb_height, $size[0], $size[1]);

   // write output image
   imagejpeg($dst_img, $my_output_file, $jpeg_quality);

   // free memory used
   imagedestroy($src_img);
   imagedestroy($dst_img);
   echo "done";

}

}

?>

 

anything