Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload in another folder whit resize #2955

Closed
vahidalvandi opened this issue Jul 1, 2019 · 5 comments
Closed

upload in another folder whit resize #2955

vahidalvandi opened this issue Jul 1, 2019 · 5 comments
Labels

Comments

@vahidalvandi
Copy link

vahidalvandi commented Jul 1, 2019

i follow this link (i use laravel) and i use last version el-finder
#1331
but not work !!

please see this config file for laravel elfinder
https://github.com/barryvdh/laravel-elfinder/blob/master/config/elfinder.php

it have 'options' i use it for bind

    'options' => array(
      'bind' => array(
          'upload.presave' => array('Plugin.AutoResize.onUpLoadPreSave'),
          'upload resize' => array(new App\genResize, 'smallImage'),
       ),
      'plugin' => array(
          'AutoResize' => array(
          'enable' => true,
          'maxWidth'  => 800,
          'quality' => 95
          )
      ),
    ),

and this my class

<?php
	namespace App;

		class genResize {

				function  smallImage($cmd, $result, $args, $elfinder, $volume) {
		    // make image maxsize
		    $maxWidth = 300;
		    $maxHeight = 300;
		    $jpgQuality = 70;

		    $smallsDir = public_path('files/.smallSize') ;


		    if ($volume && $result && isset($result['added'])) {
		        foreach($result['added'] as $item) {



		            if ($file = $volume->file($item['hash'])) {
		                $path = $volume->getPath($item['hash']);
		                if (strpos($file['mime'], 'image/') === 0 && ($srcImgInfo = @getimagesize($path))) {
		                    $zoom = min(($maxWidth/$srcImgInfo[0]),($maxHeight/$srcImgInfo[1]));
		                    $width = round($srcImgInfo[0] * $zoom);
		                    $height = round($srcImgInfo[1] * $zoom);
		                    $tfp = tmpfile();
		                    $info = stream_get_meta_data($tfp);
		                    $temp = $info['uri'];
		                    if ($src = fopen($path, 'rb')) {
		                        stream_copy_to_stream($src, $tfp);
		                        fclose($src);
		                        if ($volume->imageUtil('resize', $temp, compact('width', 'height', 'jpgQuality'))) {
		                            @copy($temp, $smallsDir . '/' . $file['name']);
		                        }
		                    }
		                }
		            }
		        }
		    }
		}
}

but $volume is null and cant run continue ..

		                        if ($volume->imageUtil('resize', $temp, compact('width', 'height', 'jpgQuality'))) {
		                            @copy($temp, $smallsDir . '/' . $file['name']);
		                        }
@nao-pon
Copy link
Member

nao-pon commented Jul 12, 2019

@vahidalvandi I tested with the standalone elFinder. $volume can be obtained correctly. You can also check out the standalone elFinder.

@vahidalvandi
Copy link
Author

i tested it in laravel

@vahidalvandi
Copy link
Author

how i can copy resize in another folder with same folder structure ?? my code copy it in root .small folder !

@vahidalvandi
Copy link
Author

please show full document create and resize in another path also change and remove from src image

@nao-pon
Copy link
Member

nao-pon commented Jul 31, 2019

@vahidalvandi The code is copied with PHP's copy function so copy it wherever you want.

@nao-pon nao-pon closed this as completed Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants