mirror of
https://github.com/typemill/typemill.git
synced 2025-08-06 14:16:46 +02:00
Version 1.3.7: Resize and grayscale images on the fly
This commit is contained in:
@@ -6,22 +6,22 @@ use \URLify;
|
||||
class ProcessAssets
|
||||
{
|
||||
# holds the path to the baseFolder
|
||||
protected $baseFolder;
|
||||
public $baseFolder;
|
||||
|
||||
# holds the path to the mediaFolder
|
||||
protected $mediaFolder;
|
||||
public $mediaFolder;
|
||||
|
||||
# holds the path to the temporary image folder
|
||||
protected $tmpFolder;
|
||||
public $tmpFolder;
|
||||
|
||||
# holds the path where original images are stored
|
||||
protected $originalFolder;
|
||||
public $originalFolder;
|
||||
|
||||
# holds the path where images for frontend use are stored
|
||||
protected $liveFolder;
|
||||
public $liveFolder;
|
||||
|
||||
# holds the folder where the thumbs for the media library are stored
|
||||
protected $thumbFolder;
|
||||
public $thumbFolder;
|
||||
|
||||
# holds the folder where the thumbs for the media library are stored
|
||||
public $fileFolder;
|
||||
@@ -43,6 +43,8 @@ class ProcessAssets
|
||||
|
||||
$this->thumbFolder = $this->mediaFolder . 'thumbs' . DIRECTORY_SEPARATOR;
|
||||
|
||||
$this->customFolder = $this->mediaFolder . 'custom' . DIRECTORY_SEPARATOR;
|
||||
|
||||
$this->fileFolder = $this->mediaFolder . 'files' . DIRECTORY_SEPARATOR;
|
||||
|
||||
$this->desiredSizes = $desiredSizes;
|
||||
@@ -55,7 +57,7 @@ class ProcessAssets
|
||||
|
||||
if($forassets == 'images')
|
||||
{
|
||||
$folders = [$this->mediaFolder, $this->tmpFolder, $this->originalFolder, $this->liveFolder, $this->thumbFolder];
|
||||
$folders = [$this->mediaFolder, $this->tmpFolder, $this->originalFolder, $this->liveFolder, $this->thumbFolder, $this->customFolder];
|
||||
}
|
||||
|
||||
foreach($folders as $folder)
|
||||
|
@@ -257,19 +257,19 @@ class ProcessImage extends ProcessAssets
|
||||
$result = false;
|
||||
}
|
||||
|
||||
# you should not use glob but exact name with ending
|
||||
/*
|
||||
foreach(glob($this->originalFolder . $name) as $image)
|
||||
# delete custom images (resized and grayscaled)
|
||||
# array_map('unlink', glob("some/dir/*.txt"));
|
||||
$pathinfo = pathinfo($name);
|
||||
|
||||
foreach(glob($this->customFolder . $pathinfo['filename'] . '\-*.' . $pathinfo['extension']) as $image)
|
||||
{
|
||||
# you could check if extension is the same here
|
||||
if(!unlink($image))
|
||||
{
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
# array_map('unlink', glob("some/dir/*.txt"));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -350,15 +350,8 @@ class ProcessImage extends ProcessAssets
|
||||
$this->setFileName($filename, 'image', $overwrite = true);
|
||||
|
||||
# if($this->extension == 'jpg') $this->extension = 'jpeg';
|
||||
|
||||
switch($this->extension)
|
||||
{
|
||||
case 'gif': $image = imagecreatefromgif($this->liveFolder . $filename); break;
|
||||
case 'jpg' :
|
||||
case 'jpeg': $image = imagecreatefromjpeg($this->liveFolder . $filename); break;
|
||||
case 'png': $image = imagecreatefrompng($this->liveFolder . $filename); break;
|
||||
default: return 'image type not supported';
|
||||
}
|
||||
|
||||
$image = $this->createImageFromPath($this->liveFolder . $filename, $this->extension);
|
||||
|
||||
$originalSize = $this->getImageSize($image);
|
||||
|
||||
@@ -374,20 +367,14 @@ class ProcessImage extends ProcessAssets
|
||||
return false;
|
||||
}
|
||||
|
||||
public function generateSizesFromImageFile($filename, $image)
|
||||
# filename and imagepath can be a tmp-version after upload.
|
||||
public function generateSizesFromImageFile($filename, $imagePath)
|
||||
{
|
||||
$this->setFileName($filename, 'image');
|
||||
|
||||
if($this->extension == 'jpg') $this->extension = 'jpeg';
|
||||
|
||||
switch($this->extension)
|
||||
{
|
||||
case 'gif': $image = imagecreatefromgif($image); break;
|
||||
case 'jpg' :
|
||||
case 'jpeg': $image = imagecreatefromjpeg($image); break;
|
||||
case 'png': $image = imagecreatefrompng($image); break;
|
||||
default: return 'image type not supported';
|
||||
}
|
||||
# if($this->extension == 'jpg') $this->extension = 'jpeg';
|
||||
|
||||
$image = $this->createImageFromPath($imagePath, $this->extension);
|
||||
|
||||
$originalSize = $this->getImageSize($image);
|
||||
|
||||
@@ -395,4 +382,27 @@ class ProcessImage extends ProcessAssets
|
||||
|
||||
return $resizedImages;
|
||||
}
|
||||
|
||||
public function grayscale($imagePath, $extension)
|
||||
{
|
||||
$image = $this->createImageFromPath($imagePath, $extension);
|
||||
|
||||
imagefilter($image, IMG_FILTER_GRAYSCALE);
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
public function createImageFromPath($imagePath, $extension)
|
||||
{
|
||||
switch($extension)
|
||||
{
|
||||
case 'gif': $image = imagecreatefromgif($imagePath); break;
|
||||
case 'jpg' :
|
||||
case 'jpeg': $image = imagecreatefromjpeg($imagePath); break;
|
||||
case 'png': $image = imagecreatefrompng($imagePath); break;
|
||||
default: return 'image type not supported';
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user