public function save() { $dgClass = new dg(); if (!empty($_POST)) { $art = $_POST['art']; if (isset($_FILES["file"]["name"]) && $_FILES["file"]["name"] != '') { // create folder $root = dirname(ROOT) . DS . 'uploaded' . DS . 'cliparts' . DS . $art['cate_id']; if (!file_exists($root)) { mkdir($root, 0755, TRUE); } $upload_path = $root . DS . 'print' . DS; if (!is_dir($upload_path)) { mkdir($upload_path, 0755, TRUE); } // upload file require_once dirname(ROOT) . DS . 'includes' . DS . 'upload.php'; $uploader = new Uploader(); $uploader->setDir($upload_path); $uploader->setExtensions(array('jpg', 'jpeg', 'png', 'gif', 'svg')); $uploader->setMaxSize(10); $uploader->sameName(false); if ($uploader->uploadFile('file')) { $image = $uploader->getUploadName(); $extension = $uploader->getExtension($image); $extension = strtolower($extension); $url = site_url('uploaded/cliparts/'); $url = str_replace('/admin/', '/', $url); $art['file_type'] = $extension; $art['file_name'] = $image; $art['path'] = $url; $art['url'] = $url . $art['cate_id'] . '/'; // create folder thumb $thumbs = $root . DS . 'thumbs'; if (!is_dir($thumbs)) { mkdir($thumbs, 0755, TRUE); } $medium = $root . DS . 'medium'; if (!is_dir($medium)) { mkdir($medium, 0755, TRUE); } if ($extension == 'svg') { $art['change_color'] = 1; $art['thumb'] = 'print/' . $image; $art['medium'] = 'print/' . $image; } else { require_once ROOT . DS . 'includes' . DS . 'thumb.php'; $thumb = new thumb($upload_path . $image); $thumb->resize(null, 100, 100, $thumbs . DS . md5($image) . '.' . $extension); $thumb->resize(null, 300, 300, $medium . DS . md5($image . 'medium') . '.' . $extension); $art['thumb'] = 'thumbs/' . md5($image) . '.' . $extension; $art['medium'] = '/medium/' . md5($image . 'medium') . '.' . $extension; $art['change_color'] = 0; } } else { echo $uploader->getMessage(); } } $art['price'] = (double) $art['price']; $file = dirname(ROOT) . DS . 'data' . DS . 'arts.json'; // check file if (!file_exists($file)) { $dgClass->redirect('index.php/clipart'); return; } $data = file_get_contents($file); $arts = json_decode($data); $is_new = true; $conent = array(); if (isset($_POST['id']) && $_POST['id'] > 0) { $id = $_POST['id']; // update clipart if (isset($arts->arts) && count($arts->arts) > 0) { foreach ($arts->arts as $row) { if ($row->clipart_id == $id) { $art['clipart_id'] = $id; $conent[] = $art; $is_new = false; } else { $conent[] = $row; } } } } if ($is_new === true) { $index = 0; foreach ($arts->arts as $row) { if ($row->clipart_id > $index) { $index = $row->clipart_id; } $conent[] = $row; } $art['clipart_id'] = $index + 1; $conent[] = $art; $arts->count = $arts->count + 1; } $arts->arts = $conent; $dgClass->WriteFile($file, json_encode($arts)); $dgClass->redirect('index.php/clipart'); } else { $dgClass->redirect('index.php/clipart'); } }
function create_image($source, $route, $new_w) { require_once 'thumbnails.php'; $image = new thumb(); $image->loadImage($source); $image->resize($new_w, 'width'); $image->save($route, 100); }
function pruebaresize($url, $filename, $w, $h, $sel_width, $sel_height, $sel_x, $sel_y) { $len = strlen($filename); $pos = strripos($filename, "."); $ext = strtolower(substr($filename, ($len - $pos - 1) * -1)); $base = substr($filename, 0, $pos); $newImage = $base . "-" . $w . "x" . $h . "." . $ext; $mythumb = new thumb(); $mythumb->loadImage($url . $filename); $mythumb->crop($sel_width, $sel_height, $sel_x, $sel_y); $mythumb->save($url . $newImage); $mythumb = new thumb(); $mythumb->loadImage($url . $newImage); $mythumb->resize($h, 'height'); $mythumb->save($url . $newImage); }
<?php header('Content-Type: image/jpg'); include_once 'thumb.php'; $nombreImg = isset($_GET["img"]) ? $_GET["img"] : "avatarimg"; $resolution = isset($_GET["size"]) ? $_GET["size"] : "100-w"; if ($resolution == '') { $resolution = "100-w"; } if ($nombreImg == '') { $nombreImg = "avatarimg.jpg"; } $widthheight = array("w" => "width", "h" => "height"); list($pixeles, $orientacion) = explode("-", $resolution); $mythumb = new thumb(); $mythumb->loadImage("../../img/" . $nombreImg); $mythumb->resize($pixeles, $widthheight[$orientacion]); $mythumb->show();