Ejemplo n.º 1
0
 /**
  * 图片裁剪
  */
 public function crop($subfix = '')
 {
     C('DEFAULT_AJAX_RETURN', 'json');
     $imgUrl = I('post.imgUrl');
     $image = file_read_remote($imgUrl);
     if ($image) {
         $param = array('width' => I('post.imgW', 0, 'ceil'), 'height' => I('post.imgH', 0, 'ceil'), 'y' => I('post.imgY1', 0, 'ceil'), 'x' => I('post.imgX1', 0, 'ceil'), 'w' => I('post.cropW', 0, 'ceil'), 'h' => I('post.cropH', 0, 'ceil'));
         $imgPath = UPLOAD_PATH . date('Y/m/d/') . basename($imgUrl);
         $newImage = file_subfix($imgPath, $subfix);
         $res = image_crop($param, $image, false, $newImage);
         if ($res) {
             $response = array('status' => 1, 'info' => '裁剪成功', 'url' => file_full_path($newImage));
         } else {
             $response = array('status' => 0, 'info' => '图片裁剪失败');
         }
     } else {
         $response = array('status' => 0, 'info' => '图片读取失败');
     }
     $this->ajaxReturn($response);
 }
Ejemplo n.º 2
0
<?php

/*
 Title: Image Cropper
 Author:  RP Development
 Date: October 10,2015
 http://rpdev.lk
*/
if (isset($_POST['crop'])) {
    $varArr = explode(",", $_POST['points']);
    image_crop($varArr[0], $varArr[1], $varArr[2], $varArr[3], $_POST['img'], $_POST['width'], $_POST['height']);
}
function image_crop($top, $right, $bottom, $left, $image_location, $width, $height)
{
    echo $top . "," . $right . "," . $bottom . "," . $left . "," . $image_location . "," . $width . "," . $height;
    $topF = $top;
    $rightF = $right;
    $bottomF = $bottom;
    $leftF = $left;
    $image = $image_location;
    $fileName = explode('.', $image);
    //Get Image Size
    list($widthPresent, $heightPresent) = getimagesize($image);
    $newWidth = $width;
    $newHeight = $height;
    $thumb = imagecreatetruecolor($newWidth, $newHeight);
    $source = imagecreatefromjpeg($image);
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $newWidth, $newHeight, $widthPresent, $heightPresent);
    imagejpeg($thumb, $fileName[0] . "_temp.jpg", 100);
    $img = imagecreatefromjpeg($fileName[0] . "_temp.jpg");
    $final = imagecreatetruecolor($rightF, $bottomF);
 */
session_name("Upload");
session_start();
if (isset($_POST['acao']) && $_POST['acao'] == 'Enviar') {
    $file = $_FILES['foto'];
    $dir = 'uploads/';
    $file_name = $file['name'];
    $file_tmp_name = $file['tmp_name'];
    if (!is_dir($dir)) {
        @mkdir($dir);
    }
    $ext = strtolower(strrchr($file_name, "."));
    $nome_img = md5(uniqid($file_name)) . $ext;
    $nome_tmb = "200x200-" . $nome_img;
    image_crop($file_tmp_name, $dir, $nome_img, 900, 600, false);
    image_crop($file_tmp_name, $dir, $nome_tmb, 200, 200, true);
    files_dir($dir);
}
if (isset($_POST['src']) && !empty($_POST['src'])) {
    $src = $_POST['src'];
    $exp = explode('/', $_POST['src']);
    $dir = $exp[0];
    $file = $exp[1];
    if (file_exists($src)) {
        @unlink($src);
        // Removemos a imagem thumb
        @unlink($dir . '/' . str_replace('200x200-', '', $file));
        // removemos a imagem grande
        echo '<div class="alert">Imagem removida com sucesso!</div>';
        // retornamos uma mensagem
        files_dir($dir . '/');
Ejemplo n.º 4
0
function image_save($id, $params, &$error = null)
{
    switch ($params['type']) {
        case 'copy':
            $p['file'] = $params['out'] . $id . '.' . $params['ext'];
            if (!copy($params['in'], $p['file'])) {
                $error = 'Copying the image to "' . $p['file'] . '" failed. The most likely cause of this is the folder permissions of the destination folder. Please make sure scripts have access to write in this folder.';
                return false;
            }
            break;
        case 'crop':
            $image = array('image' => $params['in'], 'thumb' => $params['out'] . $id . '.' . $params['ext']);
            if (is_array($params['size'])) {
                $image = array_merge($image, $params['size']);
            } elseif (function_exists($params['size'])) {
                $params['size']($image);
            }
            if ($params['imagick']) {
                if (!image_crop_im($image, $error)) {
                    return false;
                }
            } else {
                if (!image_crop($image, $error)) {
                    return false;
                }
            }
            break;
        case 'store':
            $image = array('temp' => $params['in'], 'file' => $params['out'] . $id, 'ext' => $params['ext']);
            if (is_array($params['size'])) {
                $image = array_merge($image, $params['size']);
            } elseif (function_exists($params['size'])) {
                $params['size']($image);
            }
            if ($params['imagick']) {
                if (!image_store_im($image, $error)) {
                    return false;
                }
            } else {
                if (!image_store($image, $error)) {
                    return false;
                }
            }
            break;
        default:
            $error = 'You must specify an image save type.';
            return false;
    }
    return true;
}