PHP Classes

File: assets/jcrop/demos/crop.php

Recommend this page to a friend!
  Classes of Danish Satti  >  Upload and Crop  >  assets/jcrop/demos/crop.php  >  Download  
File: assets/jcrop/demos/crop.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Upload and Crop
Validate and crop uploaded images files
Author: By
Last change:
Date: 7 years ago
Size: 2,935 bytes


Class file image Download

 * Jcrop image cropping plugin for jQuery
 * Example cropping script
 * @copyright 2008-2009 Kelly Hallman
 * More info:

$targ_w = $targ_h = 150;
$jpeg_quality = 90;

$src = 'demo_files/pool.jpg';
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );


header('Content-type: image/jpeg');


// If not a POST request, display page below:

?><!DOCTYPE html>
<html lang="en">
  <title>Live Cropping Demo</title>
  <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
  <script src="../js/jquery.min.js"></script>
  <script src="../js/jquery.Jcrop.js"></script>
  <link rel="stylesheet" href="demo_files/main.css" type="text/css" />
  <link rel="stylesheet" href="demo_files/demos.css" type="text/css" />
  <link rel="stylesheet" href="../css/jquery.Jcrop.css" type="text/css" />

<script type="text/javascript">


      aspectRatio: 1,
      onSelect: updateCoords


  function updateCoords(c)

  function checkCoords()
    if (parseInt($('#w').val())) return true;
    alert('Please select a crop region then press submit.');
    return false;

<style type="text/css">
  #target {
    background-color: #ccc;
    width: 500px;
    height: 330px;
    font-size: 24px;
    display: block;



<div class="container">
<div class="row">
<div class="span12">
<div class="jc-demo-box">

<div class="page-header">
<ul class="breadcrumb first">
  <li><a href="../index.html">Jcrop</a> <span class="divider">/</span></li>
  <li><a href="../index.html">Demos</a> <span class="divider">/</span></li>
  <li class="active">Live Demo (Requires PHP)</li>
<h1>Server-based Cropping Behavior</h1>

        <!-- This is the image we're attaching Jcrop to -->
        <img src="demo_files/pool.jpg" id="cropbox" />

        <!-- This is the form that our event handler fills -->
        <form action="crop.php" 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 type="submit" value="Crop Image" class="btn btn-large btn-inverse" />

            <b>An example server-side crop script.</b> Hidden form values
            are set when a selection is made. If you press the <i>Crop Image</i>
            button, the form will be submitted and a 150x150 thumbnail will be
            dumped to the browser. Try it!



For more information send a message to info at phpclasses dot org.