crop() public méthode

include the Zebra_Image library require 'path/to/Zebra_Image.php'; instantiate the class $img = new Zebra_Image(); a source image $img->source_path = 'path/to/source.ext'; path to where should the resulting image be saved note that by simply setting a different extension to the file will instruct the script to create an image of that particular type $img->target_path = 'path/to/target.ext'; crop a rectangle of 100x100 pixels, starting from the top-left corner $img->crop(0, 0, 100, 100);
public crop ( integer $start_x, integer $start_y, integer $end_x, integer $end_y ) : boolean
$start_x integer x coordinate to start cropping from @param integer $start_y y coordinate to start cropping from @param integer $end_x x coordinate where to end the cropping @param integer $end_y y coordinate where to end the cropping @since 1.0.4 @return boolean Returns TRUE on success or FALSE on error. If FALSE is returned, check the {@link error} property to see the error code.
$start_y integer
$end_x integer
$end_y integer
Résultat boolean
Exemple #1
0
function cropImage(&$image, $request)
{
    if (!$image['result']) {
        return;
    }
    $cropWidthCount = array_key_exists('cropWidthCount', $request) ? $request['cropWidthCount'] : false;
    $cropHeightCount = array_key_exists('cropHeightCount', $request) ? $request['cropHeightCount'] : false;
    if ($cropWidthCount === false && $cropHeightCount === false) {
        return;
    }
    list($width, $height) = getimagesize($image['url']);
    for ($h = 0; $h < $cropHeightCount; ++$h) {
        for ($w = 0; $w < $cropWidthCount; ++$w) {
            $zebraImage = new Zebra_Image();
            $zebraImage->source_path = $image['url'];
            $zebraImage->target_path = dirname($image['url']) . DIRECTORY_SEPARATOR . basename($image['url'], '.' . pathinfo($image['url'], PATHINFO_EXTENSION)) . "_{$w}_{$h}" . '.' . pathinfo($image['url'], PATHINFO_EXTENSION);
            $zebraImage->jpeg_quality = 100;
            $image['result'] = $zebraImage->crop(($w + 0) * $width / $cropWidthCount, ($h + 0) * $height / $cropHeightCount, ($w + 1) * $width / $cropWidthCount, ($h + 1) * $height / $cropHeightCount);
            $image['status'] = extractZebraError($zebraImage);
            if (!array_key_exists('crop', $image)) {
                $image['crop'] = array();
            }
            if (!array_key_exists($h, $image['crop'])) {
                $image['crop'][$h] = array();
            }
            $image['crop'][$h][$w] = array('url' => $zebraImage->target_path);
        }
    }
}
Exemple #2
0
<?php

$imgCrop = new Zebra_Image();
$imgCrop->source_path = "../upload/temporal_{$_REQUEST['imagen']}";
$imgCrop->target_path = "../upload/temporal_{$_REQUEST['imagen']}";
$imgCrop->jpeg_quality = 100;
$imgCrop->preserve_aspect_ratio = true;
$imgCrop->enlarge_smaller_images = true;
$imgCrop->preserve_time = true;
//SI EL CROP SE REALIZO CORRECTAMENTE RENOMBRAMOS LA IMAGEN
if ($imgCrop->crop(intval($_REQUEST[jrac_crop_x]), intval($_REQUEST[jrac_crop_y]), intval($_REQUEST[jrac_crop_width]) + intval($_REQUEST[jrac_crop_x]), intval($_REQUEST[jrac_crop_height]))) {
    if (rename("../upload/temporal_{$_REQUEST['imagen']}", "../upload/{$_REQUEST['imagen']}")) {
        $tiempoRedir = 5;
        ?>
        <html>
            <head>
                <title>Redimencion de imagen</title>
                <meta http-equiv="refresh" content="<?php 
        echo $tiempoRedir;
        ?>
; url=<?php 
        echo "../index.php?module=EDITA_EDITAR_IMAGEN&action=index&imagen={$_REQUEST['imagen']}&resultado=ok";
        ?>
" />
                <link href='//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css' rel='stylesheet'  type='text/css'/>
                <script src="https://code.jquery.com/jquery-1.8.2.min.js" type="text/javascript"></script>
                <script>
                    $(document).ready(function () {
                        var count = <?php 
        echo $tiempoRedir;
        ?>
Exemple #3
0
 // and if there is an error, show the error message
 if (!$image->flip_vertical()) {
     show_error($image->error, $image->source_path, $image->target_path);
 }
 // indicate a target image
 $image->target_path = 'results/flip-b.' . $ext;
 // flip both horizontally and vertically
 // and if there is an error, show the error message
 if (!$image->flip_both()) {
     show_error($image->error, $image->source_path, $image->target_path);
 }
 // indicate a target image
 $image->target_path = 'results/crop.' . $ext;
 // crop
 // and if there is an error, show the error message
 if (!$image->crop(0, 0, 50, 50)) {
     show_error($image->error, $image->source_path, $image->target_path);
 }
 // indicate a target image
 $image->target_path = 'results/rotate.' . $ext;
 // rotate
 // and if there is an error, show the error message
 if (!$image->rotate(45)) {
     show_error($image->error, $image->source_path, $image->target_path);
 }
 // indicate a target image
 $image->target_path = 'results/filter.' . $ext;
 // apply some filters
 // (this combination produces the "sepia" filter)
 $image->apply_filter(array(array('grayscale'), array('colorize', 90, 60, 40)));
 ?>