PHP PROJECT

README.md

Count user visits and display in a image widget

This class count user visits and display in a image widget. It can record the accesses of site visitors in a MySQL database. The class can also generate an image for a widget that displays the number of visitors of the site pages. The image widget details like font color, font style, font, background color can be configured.

Files


NameTypeSizeLast Modified
responsiveImage.php phpfile icon 2566 25 February 2016 11:41:22

Source

  1. <?php
  2. /*
  3. vishv sahdev
  4. Website: v23.in
  5. Email : vishv23@gmail.com
  6. Date : 16 January 2016
  7. Crop Scale Image
  8. <img src="responsiveImage.php?f=businesscard.jpg&w=700&h=300" alt="responsive image">
  9. */
  10. // responsiveImage.php?f=filename&w=200&h=200
  11. // http://v23.in/responsiveImage.php?f=businesscard.jpg
  12. // http://v23.in/responsiveImage.php?f=businesscard.jpg&w=700
  13. // http://v23.in/responsiveImage.php?f=businesscard.jpg&h=300
  14. // http://v23.in/responsiveImage.php?f=businesscard.jpg&w=700&h=300
  15. // requirment - Imagick
  16. //-----------------------------example-----------------
  17. if(!isset($_GET['f'])){
  18. $g=array("f"=>"businesscardtwo.jpg","w"=>500,"h"=>200);
  19. new responsiveImage($g);
  20. }
  21. else
  22. new responsiveImage($_GET);
  23. //-----------------------------------------------------
  24. //-----------------------------Class-----------------
  25. class responsiveImage
  26. {
  27. //------------------------------------Edit Images Path------------------
  28. public $imgFolder="./img/";
  29. public function __construct($g)
  30. {
  31. if(!isset($g['f']))
  32. die('Filename not found');
  33. if(isset($g['h']))
  34. $height $g['h'];
  35. elseif(isset($g['h']) && $g['h'] > 2000)
  36. $height 0;
  37. else
  38. $height 0;
  39. if(isset($g['w']))
  40. $width $g['w'];
  41. elseif(isset($g['w']) && $g['w'] > 2000)
  42. $width 0;
  43. else
  44. $width 0;
  45. $imagePath $this->imgFolder $g['f'];
  46. if(!is_file$imagePath ))
  47. die('File Not Exist...');
  48. $this->cropImage($imagePath,  $width$height);
  49. }
  50. private function  cropImage($imagePath,  $width$height) {
  51. $imagick = new Imagick($imagePath); 
  52. $d $imagick->getImageGeometry(); 
  53. $w $d['width']; 
  54. $h $d['height'];
  55. if($width == 0)
  56. $width $w;
  57. if($height == 0)
  58. $height $h;
  59. $r=$this->calculateV1($width,$height,$w,$h);
  60. $imagick->cropImage($r->width$r->height$r->startX$r->startY);
  61.     if($r->create)
  62.      $imagick->scaleImage($width,$height);
  63.     header("Content-Type: image/jpg");
  64.     echo $imagick->getImageBlob();
  65. }
  66. private function calculateV1($screenWidth,$screenHeight,$imageWidth,$imageHeight)
  67. $ww $imageWidth $screenWidth;
  68. $hh$imageHeight $screenHeight;    
  69.     $ratio min($ww$hh);
  70.     if($ratio 1){
  71.     $w ceil($screenWidth $ratio);
  72.     $h ceil($screenHeight $ratio);
  73.     $o=true;
  74.     }
  75.     else
  76.     {
  77.     $w ceil($screenWidth);
  78.     $h ceil($screenHeight);
  79.     $o=false;
  80.     }
  81.     
  82.     $x ceil(($imageWidth $screenWidth )   / 2);
  83.     $y ceil(($imageHeight $screenHeight )  / 2);
  84.     
  85.         
  86. return json_decode(json_encode(array("create"=>$o,"width"=>$w,"height"=>$h,"startX"=>$x,"startY"=>$y),true));
  87. }
  88. }
  89. ?>

Demo

You can find a demo available here: Hit Counter

Requirment

  • mySql
  • PHP >= 5.4
  • Apache Server

Contribute

  • Vishv Sahdev

Example

>>

Download