예제 #1
0
 /**
  * Remove the specified resource from storage.
  * DELETE /adminimages/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $file = Input::get('image');
     $path = public_path() . '/assets/uploads/img/';
     if (!File::delete($path . $file)) {
         Session::flash('flash_message', 'Error deleting image!');
     } else {
         Session::flash('flash_message', 'Image has been deleted');
     }
     //
     Image::destroy($id);
     return Redirect::route('admin.images');
 }
예제 #2
0
 public function destroy($projectId, $imageId)
 {
     $image = Image::find($imageId);
     $destinationPath = public_path() . '/uploads/images/';
     if ($image->project_id == $projectId) {
         if (Image::destroy($imageId)) {
             File::delete($destinationPath . $image->path);
             return Response::json(['alert' => Messages::$deleteSuccess . 'image']);
         } else {
             return Response::json(['alert' => Messages::$deleteFail . 'image'], 404);
         }
     }
 }
예제 #3
0
파일: benchmark.php 프로젝트: 0151n/vichan
function benchmark($method)
{
    global $config, $file, $extension, $out, $count;
    $config['thumb_method'] = $method;
    printf("Method: %s\nThumbnailing %d times... ", $method, $count);
    $start = microtime(true);
    for ($i = 0; $i < $count; $i++) {
        $image = new Image($file, $extension);
        $thumb = $image->resize($config['thumb_ext'] ? $config['thumb_ext'] : $extension, $config['thumb_width'], $config['thumb_height']);
        $thumb->to($out);
        $thumb->_destroy();
        $image->destroy();
    }
    $end = microtime(true);
    printf("Took %.2f seconds (%.2f/second; %.2f ms)\n", $end - $start, $rate = $count / ($end - $start), 1000 / $rate);
    unlink($out);
}
예제 #4
0
파일: add.php 프로젝트: jinshana/tangocms
 /**
  * Handles the uploading and image post-processing if needed.
  *
  * @param array $fd
  * @return array
  */
 protected function handleUpload(array $fd)
 {
     try {
         $uploader = new Uploader('media_file', $this->_zula->getDir('uploads') . '/media/' . $fd['cid'] . '/{CATEGORY}');
         $uploader->subDirectories()->allowedMime($this->allowedMime)->maxFileSize($this->_config->get('media/max_fs'))->extractArchives();
         $file = $uploader->getFile();
         if ($file->upload() === false) {
             throw new Media_Exception(t('Please select a file to upload'));
         }
         // Upload the thumbail image if one has been provided and resize it
         $thumbnailWH = $this->_config->get('media/thumb_dimension');
         $thumbUploader = new Uploader('media_thumb', $file->dirname);
         $thumbUploader->subDirectories(false)->allowImages();
         $thumbnail = $thumbUploader->getFile();
         if ($thumbnail->upload() !== false) {
             $thumbImage = new Image($thumbnail->path);
             $thumbImage->mime = 'image/png';
             $thumbImage->thumbnail($thumbnailWH, $thumbnailWH);
             // Remove the original uploaded file
             unlink($thumbnail->path);
         }
         /**
          * Get details of all the images (could have been an archive containing
          * multiple media files
          */
         $uploadedItems = array();
         while ($details = $file->getDetails()) {
             if (isset($details['path'])) {
                 // Get the directory name where the files are stored (just the name, not path)
                 $dirname = substr($details['dirname'], strrpos($details['dirname'], DIRECTORY_SEPARATOR) + 1);
                 /**
                  * Use uploaded thumbnail, or attempt to create one from the uploaded image
                  */
                 $thumbname = $details['filename'] . '_thumb.png';
                 if (isset($thumbImage)) {
                     $thumbImage->save($details['dirname'] . '/' . $thumbname, false);
                 } else {
                     if ($details['category'] == 'image') {
                         $tmpThumb = new Image($details['path']);
                         $tmpThumb->mime = 'image/png';
                         $tmpThumb->thumbnail($thumbnailWH, $thumbnailWH)->save($details['dirname'] . '/' . $thumbname);
                     } else {
                         unset($thumbname);
                     }
                 }
                 // Generate a title from the filename automatically
                 $title = str_replace(array('-', '_', '+'), ' ', pathinfo($details['name'], PATHINFO_FILENAME));
                 $uploadedItems[] = array('title' => trim(ucfirst(strtolower($title))), 'desc' => '', 'type' => $details['category'], 'file' => $dirname . '/' . $details['basename'], 'thumbnail' => isset($thumbname) ? $dirname . '/' . $thumbname : '');
             }
         }
         if (isset($thumbImage)) {
             $thumbImage->destroy();
         }
         return $uploadedItems;
     } catch (Uploader_NotEnabled $e) {
         $msg = t('Sorry, it appears file uploads are disabled within your PHP configuration');
     } catch (Uploader_MaxFileSize $e) {
         $msg = sprintf(t('Selected file exceeds the maximum allowed file size of %s'), zula_human_readable($e->getMessage()));
     } catch (Uploader_InvalidMime $e) {
         $msg = t('Sorry, the uploaded file is of the wrong file type');
     } catch (Uploader_Exception $e) {
         $logMsg = $e->getMessage();
         $msg = t('Oops, an error occurred while uploading your files');
     } catch (Image_Exception $e) {
         $logMsg = $e->getMessage();
         $msg = t('Oops, an error occurred while processing an image');
     }
     // Cleanup and end processing, it failed.
     if (isset($file->dirname)) {
         zula_full_rmdir($file->dirname);
     }
     if (isset($logMsg)) {
         $this->_log->message($logMsg, Log::L_WARNING);
     }
     throw new Media_Exception($msg);
 }
예제 #5
0
파일: post.php 프로젝트: fugeris/8chan
         $thumb->to($file['thumb']);
         $file['thumbwidth'] = $thumb->width;
         $file['thumbheight'] = $thumb->height;
         $thumb->_destroy();
     }
     if ($config['redraw_image'] || !@$file['exif_stripped'] && $config['strip_exif'] && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg')) {
         if (!$config['redraw_image'] && $config['use_exiftool']) {
             if ($error = shell_exec_error('exiftool -overwrite_original -ignoreMinorErrors -q -q -all= ' . escapeshellarg($file['tmp_name']))) {
                 error(_('Could not strip EXIF metadata!'), null, $error);
             }
         } else {
             $image->to($file['file']);
             $dont_copy_file = true;
         }
     }
     $image->destroy();
 } else {
     // not an image
     //copy($config['file_thumb'], $post['thumb']);
     $file['thumb'] = 'file';
     $size = @getimagesize(sprintf($config['file_thumb'], isset($config['file_icons'][$file['extension']]) ? $config['file_icons'][$file['extension']] : $config['file_icons']['default']));
     $file['thumbwidth'] = $size[0];
     $file['thumbheight'] = $size[1];
 }
 if (!isset($dont_copy_file) || !$dont_copy_file) {
     if (isset($file['file_tmp'])) {
         if (!@rename($file['tmp_name'], $file['file'])) {
             error($config['error']['nomove']);
         }
         chmod($file['file'], 0644);
     } elseif (!@move_uploaded_file($file['tmp_name'], $file['file'])) {
예제 #6
0
            file_put_contents($originPath, $data);
            $isNotExists = false;
            break;
        }
    }
    if ($isNotExists) {
        error404();
    }
}
if ($params['type'] !== 'origin') {
    $Image = new Image();
    $Image->set($originPath);
    $Image->{$params['type']}(intval($params['width']), intval($params['height']));
    mkdir_deep($requestUrl);
    $Image->output($requestUrl, intval($params['quality']));
    $Image->destroy();
}
header('Content-type: image/jpeg');
@readfile($requestUrl);
/*
 * ディレクトリ作成
 */
function mkdir_deep($path)
{
    $dirs = explode('/', dirname($path));
    $path = '';
    foreach ($dirs as $dir) {
        $path .= $dir;
        if (!is_dir($path)) {
            @mkdir($path);
            @chmod($path, 0777);
예제 #7
0
파일: Base.php 프로젝트: jinshana/tangocms
 /**
  * Copies the provided image into the current open image at set locations
  * which is mainly used for watermarks
  *
  * @param string $file
  * @param string $position
  * @return object
  */
 public function watermark($file, $position = 'bl')
 {
     $wmImage = new Image($file);
     if (!in_array($position, array('t', 'tr', 'r', 'br', 'b', 'bl', 'l', 'tl'))) {
         trigger_error('Image_Base::watermark() invalid value for argument 2, reverting to "bl"', E_USER_NOTICE);
         $position = 'bl';
     }
     // Work out position
     $posX = $posY = 0;
     if (substr($position, -1, 1) == 'r') {
         $posX = $this->width - $wmImage->width;
     } else {
         if ($position == 't' || $position == 'b') {
             $posX = ($this->width - $wmImage->width) / 2;
         }
     }
     if ($position[0] == 'b') {
         $posY = $this->height - $wmImage->height;
     } else {
         if ($position == 'l' || $position == 'r') {
             $posY = ($this->height - $wmImage->height) / 2;
         }
     }
     imagecopymerge($this->resource, $wmImage->getResource(), $posX, $posY, 0, 0, $wmImage->width, $wmImage->height, 100);
     $wmImage->destroy();
     return $this;
 }
예제 #8
0
 public function destroy($id)
 {
     Image::destroy($id);
     return Redirect::back();
 }
예제 #9
0
 /**
  * @param int $position
  * @param string $fileName
  * @param int $width
  * @param int $height
  * @return void
  */
 public function watermark($fileName, $position = self::WM_POS_BOTTOM_RIGHT, $width = null, $height = null)
 {
     if (!$this->sourceImage) {
         $this->error('NotLoaded');
     }
     $watermark = new Image($fileName);
     if ($width || $height) {
         $watermark->resize($width, $height, self::RESIZE_TYPE_STRICT);
     }
     $this->workingImage = $this->createImage($this->originalSize[0], $this->originalSize[1]);
     imagealphablending($this->workingImage, true);
     switch ($position) {
         case self::WM_POS_TOP_LEFT:
             $x = $y = $this->watermarkOffset;
             break;
         case self::WM_POS_TOP_RIGHT:
             $x = $this->originalSize[0] - $watermark->getWidth() - $this->watermarkOffset;
             $y = $this->watermarkOffset;
             break;
         case self::WM_POS_BOTTOM_RIGHT:
             $x = $this->originalSize[0] - $watermark->getWidth() - $this->watermarkOffset;
             $y = $this->originalSize[1] - $watermark->getHeight() - $this->watermarkOffset;
             break;
         case self::WM_POS_BOTTOM_LEFT:
             $x = $y = $this->watermarkOffset;
             $y = $this->originalSize[1] - $watermark->getHeight() - $this->watermarkOffset;
             break;
         case self::WM_POS_CENTER:
             $x = ($this->originalSize[0] - $watermark->getWidth()) / 2;
             $y = ($this->originalSize[1] - $watermark->getHeight()) / 2;
             break;
         default:
             $x = 0;
             $y = 0;
             break;
     }
     imagecopy($this->workingImage, $this->sourceImage, 0, 0, 0, 0, $this->originalSize[0], $this->originalSize[1]);
     imagecopy($this->workingImage, $watermark->getSourceImage(), $x, $y, 0, 0, $watermark->getWidth(), $watermark->getHeight());
     $this->replaceAndReset($this->originalSize[0], $this->originalSize[1]);
     $watermark->destroy();
 }
예제 #10
0
 public function deleteImage()
 {
     $id = Input::get('id');
     Image::destroy($id);
     return $this->success(null, null);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Image::destroy($id);
     return Redirect::route("projects.index");
 }
예제 #12
0
 /**
  * {@inheritdoc}
  *
  * @return Watermark
  */
 public function destroy()
 {
     $this->size = $this->position = null;
     $this->margin = [0, 0];
     return parent::destroy();
 }
예제 #13
0
 /**
  * Remove the specified project from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Image::destroy($id);
     return Response::json(['data' => [], 'message' => "Image Deleted"], 200);
 }