Skip to content

Commit

Permalink
PHP Code
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGarciaCat committed Feb 17, 2017
1 parent c63ff3b commit 44d5c77
Show file tree
Hide file tree
Showing 8 changed files with 2,155 additions and 0 deletions.
74 changes: 74 additions & 0 deletions ajaximage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
include('db.php');
session_start();
$session_id='1'; //$session id
$path = "uploads/";

function getExtension($str)
{

$i = strrpos($str,".");
if (!$i) { return ""; }

$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

$valid_formats = array("jpg", "png", "gif", "bmp","jpeg","PNG","JPG","JPEG","GIF","BMP");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];

if(strlen($name))
{
$ext = getExtension($name);
if(in_array($ext,$valid_formats))
{
if($size<(1024*1024))
{

require_once('class.ImageFilter.php');
$filter = new ImageFilter;
$score = $filter->GetScore($_FILES['photoimg']['tmp_name']);

if(isset($score))
{
if($score >= 40)
{
echo "Image scored ".$score."%, It seems that you have uploaded a nude picture :-(";
}

else
{

//---------
$actual_image_name = time().".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
if(move_uploaded_file($tmp, $path.$actual_image_name))
{
mysqli_query($connection,"UPDATE users SET profile_image='$actual_image_name' WHERE uid='$session_id'");

echo "<img src='uploads/".$actual_image_name."' class='preview'>";
}
else
echo "Fail upload folder with read access.";
//--------
}
}

}
else
echo "Image file size max 1 MB";
}
else
echo "Invalid file format..";
}

else
echo "Please select image..!";

exit;
}
?>
176 changes: 176 additions & 0 deletions class.ImageFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<?php
//
// +-----------------------------------+
// | Image Filter v 1.0 |
// | http://www.SysTurn.com |
// +-----------------------------------+
//
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the ISLAMIC RULES and GNU Lesser General Public
// License either version 2, or (at your option) any later version.
//
// ISLAMIC RULES should be followed and respected if they differ
// than terms of the GNU LESSER GENERAL PUBLIC LICENSE
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the license with this software;
// If not, please contact support @ S y s T u r n .com to receive a copy.
//

CLASS ImageFilter
{ #R G B
var $colorA = 7944996; #79 3B 24
var $colorB = 16696767; #FE C5 BF


var $arA = array();
var $arB = array();

function ImageFilter()
{
$this->arA['R'] = ($this->colorA >> 16) & 0xFF;
$this->arA['G'] = ($this->colorA >> 8) & 0xFF;
$this->arA['B'] = $this->colorA & 0xFF;

$this->arB['R'] = ($this->colorB >> 16) & 0xFF;
$this->arB['G'] = ($this->colorB >> 8) & 0xFF;
$this->arB['B'] = $this->colorB & 0xFF;
}

function GetScore($image)
{
$x = 0; $y = 0;
$img = $this->_GetImageResource($image, $x, $y);
if(!$img) return false;

$score = 0;

$xPoints = array($x/8, $x/4, ($x/8 + $x/4), $x-($x/8 + $x/4), $x-($x/4), $x-($x/8));
$yPoints = array($y/8, $y/4, ($y/8 + $y/4), $y-($y/8 + $y/4), $y-($y/8), $y-($y/8));
$zPoints = array($xPoints[2], $yPoints[1], $xPoints[3], $y);


for($i=1; $i<=$x; $i++)
{
for($j=1; $j<=$y; $j++)
{
$color = imagecolorat($img, $i, $j);
if($color >= $this->colorA && $color <= $this->colorB)
{
$color = array('R'=> ($color >> 16) & 0xFF, 'G'=> ($color >> 8) & 0xFF, 'B'=> $color & 0xFF);
if($color['G'] >= $this->arA['G'] && $color['G'] <= $this->arB['G'] && $color['B'] >= $this->arA['B'] && $color['B'] <= $this->arB['B'])
{
if($i >= $zPoints[0] && $j >= $zPoints[1] && $i <= $zPoints[2] && $j <= $zPoints[3])
{
$score += 3;
}
elseif($i <= $xPoints[0] || $i >=$xPoints[5] || $j <= $yPoints[0] || $j >= $yPoints[5])
{
$score += 0.10;
}
elseif($i <= $xPoints[0] || $i >=$xPoints[4] || $j <= $yPoints[0] || $j >= $yPoints[4])
{
$score += 0.40;
}
else
{
$score += 1.50;
}
}
}
}
}

imagedestroy($img);

$score = sprintf('%01.2f', ($score * 100) / ($x * $y));
if($score > 100) $score = 100;
return $score;
}

function GetScoreAndFill($image, $outputImage)
{
$x = 0; $y = 0;
$img = $this->_GetImageResource($image, $x, $y);
if(!$img) return false;

$score = 0;

$xPoints = array($x/8, $x/4, ($x/8 + $x/4), $x-($x/8 + $x/4), $x-($x/4), $x-($x/8));
$yPoints = array($y/8, $y/4, ($y/8 + $y/4), $y-($y/8 + $y/4), $y-($y/8), $y-($y/8));
$zPoints = array($xPoints[2], $yPoints[1], $xPoints[3], $y);


for($i=1; $i<=$x; $i++)
{
for($j=1; $j<=$y; $j++)
{
$color = imagecolorat($img, $i, $j);
if($color >= $this->colorA && $color <= $this->colorB)
{
$color = array('R'=> ($color >> 16) & 0xFF, 'G'=> ($color >> 8) & 0xFF, 'B'=> $color & 0xFF);
if($color['G'] >= $this->arA['G'] && $color['G'] <= $this->arB['G'] && $color['B'] >= $this->arA['B'] && $color['B'] <= $this->arB['B'])
{
if($i >= $zPoints[0] && $j >= $zPoints[1] && $i <= $zPoints[2] && $j <= $zPoints[3])
{
$score += 3;
imagefill($img, $i, $j, 16711680);
}
elseif($i <= $xPoints[0] || $i >=$xPoints[5] || $j <= $yPoints[0] || $j >= $yPoints[5])
{
$score += 0.10;
imagefill($img, $i, $j, 14540253);
}
elseif($i <= $xPoints[0] || $i >=$xPoints[4] || $j <= $yPoints[0] || $j >= $yPoints[4])
{
$score += 0.40;
imagefill($img, $i, $j, 16514887);
}
else
{
$score += 1.50;
imagefill($img, $i, $j, 512);
}
}
}
}
}
imagejpeg($img, $outputImage);

imagedestroy($img);

$score = sprintf('%01.2f', ($score * 100) / ($x * $y));
if($score > 100) $score = 100;
return $score;
}

function _GetImageResource($image, &$x, &$y)
{
$info = GetImageSize($image);

$x = $info[0];
$y = $info[1];

switch( $info[2] )
{
case IMAGETYPE_GIF:
return @ImageCreateFromGif($image);

case IMAGETYPE_JPEG:
return @ImageCreateFromJpeg($image);

case IMAGETYPE_PNG:
return @ImageCreateFromPng($image);

default:
return false;
}
}
}

?>
8 changes: 8 additions & 0 deletions db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
error_reporting(0);
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'local_db');
$connection = @mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>
85 changes: 85 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
include('db.php');
session_start();
$session_id='1'; //$session id
?>
<html>
<head>
<title>Ajax Image Upload Block Adult Images 9lessons blog</title>
</head>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery.wallform.js"></script>

<script type="text/javascript" >
$(document).ready(function() {

$('#photoimg').on('change', function() {
//$("#preview").html('');

$("#imageform").ajaxForm({target: '#preview',
beforeSubmit:function(){


$("#imageloadstatus").show();
$("#imageloadbutton").hide();
},
success:function(){

$("#imageloadstatus").hide();
$("#imageloadbutton").show();
},
error:function(){

$("#imageloadstatus").hide();
$("#imageloadbutton").show();
} }).submit();


});
});
</script>

<style>

body
{
font-family:arial;
}
.preview
{
width:200px;
border:solid 1px #dedede;
padding:10px;
}
#preview
{
color:#cc0000;
font-size:12px
}

</style>
<body>
<a href='http://9lessons.info'>9lessons.info</a>


<div style="width:600px">

<div id='preview'>
</div>



<form id="imageform" method="post" enctype="multipart/form-data" action='ajaximage.php'>
Upload your image
<div id='imageloadstatus' style='display:none'><img src="loader.gif" alt="Uploading...."/></div>
<div id='imageloadbutton'>
<input type="file" name="photoimg" id="photoimg" />
</div>
</form>



</div>
</body>
</html>
Binary file added loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 44d5c77

Please sign in to comment.