<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: shixuesen
|
|
* Date: 2019-04-15
|
|
* Time: 22:57
|
|
*/
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
use Tinify\Tinify;
|
|
|
|
class CompressImageService
|
|
{
|
|
public function compressImage()
|
|
{
|
|
\Tinify\setKey("utlyw2OipS0hdZuXptN97XdD6DnnrBsP");
|
|
// $dirs = scandir("/Volumes/Nick");
|
|
$vol = "/Volumes";
|
|
// $disk = "Seagate\\ Backup\\ Plus\\ Drive";
|
|
$dir = "/Volumes/Samsung/tpp/006/";
|
|
$files = scandir($dir);
|
|
// print_r($files);exit;
|
|
$lastOriginName = '';
|
|
foreach ($files as $file) {
|
|
// echo $file;
|
|
if ($file == '.' || $file == '..') {
|
|
continue;
|
|
}
|
|
$fileInfo = pathinfo($file);
|
|
if(strpos($file, "new")) {
|
|
continue;
|
|
} else {
|
|
if (file_exists($dir . $fileInfo['filename']."-new.".$fileInfo['extension'])) {
|
|
echo $file;
|
|
continue;
|
|
}
|
|
}
|
|
var_dump($fileInfo);
|
|
// exit;
|
|
$source = \Tinify\fromFile($dir .$file);
|
|
$source->toFile($dir.$fileInfo['filename']."-new.".$fileInfo['extension']);
|
|
// exit;
|
|
}
|
|
// var_dump($dirs);exit;
|
|
// var_dump(scandir("/Volumes/".$dirs[8]));
|
|
// var_dump($dirs);
|
|
// \Tinify\fromFile()
|
|
}
|
|
|
|
}
|