HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/rooymansde.komma-mediadesign.nl/wwwroot/kms/paginafoto_image.php
<?php

$targ_w = 120;
$targ_h = 70;
$jpeg_quality = 90;
$map = "page_images";

if(isset($_GET['pagina_id']) && isset($_GET['icon_dir'])){
    $page_id = $_GET['pagina_id'];
	$icon_dir = $_GET['icon_dir'];
	$valid_add = true;
	
	$q_image_dir = sprintf("SELECT kms_en_pages.page_id, kms_en_pages.image_dir FROM kms_en_pages WHERE kms_en_pages.page_id='%s'", $page_id);
    $r_image_dir = mysql_query($q_image_dir);
    $rec_image_dir = mysql_fetch_assoc($r_image_dir);
	
	$image_dir = $rec_image_dir['image_dir'];
	
	if(empty($image_dir)){
		$valid_add = false;
	}
	
}else{
	$valid_add = false;
}

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{

	if($_POST['w'] >= $targ_w && $_POST['h'] >= $targ_h){ 

		$src = $_SERVER['DOCUMENT_ROOT'].'/'.$map.'/'.$image_dir.'/foto_'.$icon_dir.'.jpg';
		$img_r = imagecreatefromjpeg($src);
		$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
		
		imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],$targ_w,$targ_h,$_POST['w'],$_POST['h']);
		
		$imageKleur = $dst_r;

		class image { 
		  var $in; 
		  var $out; 
		  var $table; 
		  var $w,$h; 
		  var $converted = false; 
		
		  function image($filename, $width, $height) { 
			$this->in = $filename; 
			$this->w = $width; 
			$this->h = $height; 
			$this->clear(); 
		  } 
		
		  function clear() { 
			$this->converted=false; 
			if(isset($this->out)) imagedestroy($this->out); 
			$this->out = imagecreatetruecolor($this->w,$this->h); 
		  } 
		
		  /** 
		   *  Set output to greyscale, using grey as the center duotone 
		   */ 
		  function setGrey() { 
			$this->setDuotone(196,196,196); //rgb 196 is de maximale grijswaarde
		  } 
		  /** 
		   *  Set output to duotone, using a simpler algorith resulting in a duller image 
		   */ 
		  function setDull($r,$g,$b) { 
			$this->clear(); 
			$this->table = array(); 
			for($i=0;$i<255;$i++) { 
			  $this->table[$i] = imagecolorallocate($this->out,($i+$r)/2,($i+$g)/2,($i+$b)/2); 
			} 
		  } 
		  /** 
		   *  Set output to duotone, using a fixed center color 
		   */ 
		  function setFix($r,$g,$b) { 
			$this->setDuotone($r,$g,$b,255); 
		  } 
		  /** 
		   *  Set output to duotone 
		   */ 
		  function setDuotone($r,$g,$b,$center=false,$min=196,$max=255) {  //rgb 196 is de maximale grijswaarde
			$this->clear(); 
			$this->table = array(); 
			if($center === false) $center = ($r+$g+$b)/9; //origineel is het delen door 3 
			for($i=0;$i<256;$i++) { 
			  if($this->_duotone($i,$r,$center,$min,$max) == $this->_duotone($i,$g,$center,$min,$max) && $this->_duotone($i,$g,$center,$min,$max) == $this->_duotone($i,$b,$center,$min,$max)){
				  $waarde_r = $this->_duotone($i,$r,$center,$min,$max);
				  $waarde_g = $this->_duotone($i,$g,$center,$min,$max);
				  $waarde_b = $this->_duotone($i,$b,$center,$min,$max);
				  if($waarde_r < 196){ $waarde_r = 196; $waarde_g = 196; $waarde_b = 196; } //rgb 196 is de maximale grijswaarde
			  }else{
				  $waarde_r = $this->_duotone($i,$r,$center,$min,$max);
				  $waarde_g = $this->_duotone($i,$g,$center,$min,$max);
				  $waarde_b = $this->_duotone($i,$b,$center,$min,$max);
				  echo($waarde_r);
			  }
			  $this->table[$i] = imagecolorallocate($this->out, $waarde_r, $waarde_g, $waarde_b); 
			} 
		  } 
		  /** 
		   *  Calculates the appropriate duotone color per channel 
		   */ 
		  function _duotone($black,$color,$center,$min=196,$max=255) {  //rgb 196 is de maximale grijswaarde
			if($black <= $center) { 
			  return ($black / $center) * $color; 
			} else { 
			  return $max - (($max - $black) / ($max - $center) * ($max - $color)); 
			} 
		  } 
		  /** 
		   *  Something I discoverd while trying to come up with a duotone algorithm 
		   */ 
		  function setFun($r,$g,$b) { 
			$this->clear(); 
			$this->table = array(); 
			for($i=0;$i<255;$i++) { 
			  $this->table[$i] = imagecolorallocate($this->out,(((255-$i)/255)*$i)+((($i)/255)*$r),(((255-$i)/255)*$i)+((($i)/255)*$g),(((255-$i)/255)*$i)+((($i)/255)*$b)); 
			} 
		  } 
		  /** 
		   *  Convert the image and save it in the object. 
		   */ 
		  function convert() { 
			if(!isset($this->table)) $this->setGrey(); 
			for($x=0;$x < $this->w;$x++) { 
			  for($y=0;$y < $this->h;$y++) { 
				list($r,$g,$b,$bw) = $this->_colors($x,$y); 
				imagesetpixel($this->out,$x,$y,$this->table[$bw]); 
			  } 
			} 
			$this->converted=true; 
		  } 
		  /** 
		   *  Helper function to get color information in an array/list 
		   */ 
		  function _colors($x,$y) { 
			$rgb = ImageColorAt($this->in,$x,$y); 
			$r = ($rgb >> 16) & 0xFF; 
			$g = ($rgb >> 8) & 0xFF; 
			$b = $rgb & 0xFF; 
			$bw = ($r+$g+$b)/3; // simple B/W value 
			return array($r,$g,$b,$bw); 
		  } 
		  function saveJPG($filename,$qual=90) { 
		  	if(!$this->converted) $this->convert(); 
			return imagejpeg($this->out,$filename,$qual); 
		  } 
		} 
		 
		$img = new image($imageKleur, $targ_w, $targ_h);
		$img->setDuotone(190,190,190); // rgb 185 is de duotone kleur

		$srcKleur = $_SERVER['DOCUMENT_ROOT'].'/'.$map.'/'.$image_dir.'/thumbKleur.jpg';
		
		$img->saveJPG($srcKleur); 

		$imbottom = $dst_r;
		$imtop = imagecreatefromjpeg($srcKleur);;
				
		$spriteImage=imagecreatetruecolor(imagesx($imtop),imagesy($imtop)+imagesy($imbottom));
		imagecopy($spriteImage,$imtop,0,0,0,0,imagesx($imtop),imagesy($imtop));
		imagecopy($spriteImage,$imbottom,0,imagesy($imtop),0,0,imagesx($imbottom),imagesy($imbottom));

		$file_loc= $_SERVER['DOCUMENT_ROOT'].'/'.$map.'/'.$image_dir.'/thumb_'.$icon_dir.'.jpg';
		$img_file = imagejpeg($spriteImage,$file_loc,$jpeg_quality);
		
		unlink($srcKleur);
					
		echo("<h1>Resultaat:</h1>");
		echo("<img src=\"/".$map."/".$image_dir."/thumb_".$icon_dir.".jpg\"/><br /><br />");
		echo("Pagina succesvol toegevoegd!<br /><br />");
        echo("<a href=\"index.php?p=paginafoto_toevoegen&amp;pagina_id=".$rec_image_dir['page_id']."\" title=\"Nog een foto toevoegen\">Nog een foto toevoegen</a><br /><br />");
        echo("<a href=\"index.php?p=paginafoto_overzicht&amp;pagina_id=".$rec_image_dir['page_id']."\" title=\"Foto's beheren\">Klik hier om de foto's van deze pagina te beheren</a>");
		echo("&nbsp;|&nbsp;<a href=\"index.php?p=pagina_overzicht\" title=\"Terug naar het overzicht\">Terug naar het pagina overzicht</a>");
	
		exit;
	}else{
		echo("<span class=\"error\">Maak een grotere selectie. Minimaal ".$targ_w."px x ".$targ_h."px.</span><br /><br />");
	}
}

?>
<script src="css-js/jquery.Jcrop.js"></script>
<link rel="stylesheet" href="css-js/jquery.Jcrop.css" type="text/css" />

<script language="Javascript">

    $(function(){

        $('#cropbox').Jcrop({
            aspectRatio: <?php echo($targ_w."/".$targ_h); ?>,
            onSelect: updateCoords
        });

    });

    function updateCoords(c)
    {
        $('#x').val(c.x);
        $('#y').val(c.y);
        $('#w').val(c.w);
        $('#h').val(c.h);
    };

    function checkCoords()
    {
        if (parseInt($('#w').val())) return true;
        alert('Graag eerst een vlak selecteren.');
        return false;
    };

</script>

<?php if ($valid_add){ ?>

    <div class="article">

        <h1>Thumbnail selecteren</h1>

        <img src="/page_images/<?php echo($image_dir);?>/foto_<?php echo($icon_dir);?>.jpg" id="cropbox" />

        <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" onSubmit="return checkCoords();">
            <input type="hidden" id="x" name="x" />
            <input type="hidden" id="y" name="y" />
            <input type="hidden" id="w" name="w" />
            <input type="hidden" id="h" name="h" />
            <input style="margin-left:0; margin-top:25px;" type="submit" value="Thumbnail genereren" class="submit" />
        </form>
    </div>

<?php }else{ ?>

    <div class="article">
        <h1>Geen geldige foto</h1>
        <p>De pagina waar u naar verwezen bent wijst niet naar een geldige foto.
            Controleer de betreffende pagina op fouten en controleer deze via 'pagina wijzigen'</p>
        <a href="index.php?p=pagina_overzicht" title="Terug naar het overzicht">Terug naar het pagina overzicht</a>

    </div>

<?php } ?>