Comments (14)
Hi Mariano,
Thanks a lot!
Yes stable tag is not released yet, because I'm develop it now.
But you can download dev version via composer.
composer require jbzoo/image:"3.x-dev"
Best regards, Denis.
from image.
Hi Denis,
i understand, thanks.
i report you a little writing mistake on line 331 in the dev version:
$cleanFilename = FS::clean($filename);
if (!file_exists($cleanFilename)) {
throw new Exception('Image file not forund: ' . $filename);
}
And then i want suggest you to develop a feature that can be usefull:
The possibility to load an image from string and not only from a file, this can be usefull when we want manipulate images loaded from database. Now i extended your class and i overload the constructor in order to load the image. I want share with you these few lines of code:
/**
* Enter description here ...
* @author Mariano.Pirelli
*
*/
class ImageMemory extends Image {
public function __construct($imageString) {
// Require GD library
if (!extension_loaded('gd')) {
throw new \Exception('Required extension GD is not loaded.');
}
if (empty($imageString)) {
throw new \Exception('Empty image string data');
}
if (function_exists('getimagesizefromstring')) {
//gather meta data
$info = getimagesizefromstring($imageString);
} else {
throw new \Exception('PHP 5.4 is required to use method getimagesizefromstring');
}
$this->cleanup();
$this->_mime = $info['mime'];
$this->_width = $info[0];
$this->_height = $info[1];
$this->_image = imagecreatefromstring($imageString);
$this->_exif = array();
$this->_orient = $this->_getOrientation();
imagesavealpha($this->_image, true);
imagealphablending($this->_image, true);
return $this;
}
}
Thanks for the work.
Best regards
Mariano
from image.
Yea, thanks.
I think it can be usefull, I will add support to new release.
But I think that saving images to database is nt good idea.
from image.
Oh yes i know...there are advantage and disadvantage..
I forgot to add the render method getImageData();
public function getImageData($format = 'png', $quality = null)
{
if (!$this->_image) {
throw new \Exception('Image resource not defined');
}
// Output the image
ob_start();
$mimetype = $this->_renderImageByFormat($format, null, $quality);
$imageData = ob_get_contents();
ob_end_clean();
return $imageData;
}
from image.
Great!
PS I changed your comments, fixed highlight of code.
from image.
Thank you very much.
I want suggest you just another thing. i hope that this can help:
I found that PHP under windows use the extension .tmp on uploaded files, included images, while others system don't use the extension.
So if i use a code like this an exception will be thrown:
$image = new Image($_FILES['name']['tmp_name']); // the temp file
$image->bestFit(800, 600)->save(); //save the temp file
copy($_FILES['name']['tmp_name'], $newPath); //copy the file
the exception is: Undefined format. because the format is tmp.
protected function _renderImageByFormat($format, $filename, $quality)
{
if (Helper::isJpeg($format)) {
} elseif (Helper::isPng($format)) {
} elseif (Helper::isGif($format)) {
} else {
throw new Exception('Undefined format: ' . $format);
}
return $result;
}
so i suggest this behavior:
when the method save() is called, could be better read the image format from the mime type instead from file extension, the filename is not changed so also the format, and the error above will be prevented.
while on savaAs(), read like now the format from the file name extension.
i hope that is comprensible what i wrote.
Mariano
from image.
Hi Mariano,
I jsut pushed new version to 3.x-dev
. Please try it and tell me what do you think.
Thanks.
from image.
All these features available in the 3.x version. It is stable now.
Thanks.
from image.
Hi Denis,
thanks for the new features, looks perfect.
I don't found the method to get the modified image in string format, must i use the base64 function and then convert the result ?
from image.
Hi,
You can use $string = $image->getBase64(<FORMAT>)
or $image->getImage()
to convert string manually.
May be you can sugget me some another method to convert it to string? May be with pull request?
Best regards, Denis.
from image.
Hi,
like the base64 without convertion, the binary format is:
/**
* Outputs image as binary string
*
* @param null|string $format If omitted or null - format of original file will be used, may be gif|jpg|png
* @param int|null $quality Output image quality in percents 0-100
* @return string
*
* @throws Exception
*/
public function getImageData($format = 'gif', $quality = null) or
public function getImageString($format = 'gif', $quality = null) or
public function getImageBinary($format = 'gif', $quality = null)
{
if (!$this->_image) {
throw new Exception('Image resource not defined');
}
// Output the image
ob_start();
$mimetype = $this->_renderImageByFormat($format, null, $quality);
$imageData = ob_get_contents();
ob_end_clean();
return $imageData;
}
from image.
Hi mapirelli,
Try to use getBinary() from v3.0.2
from image.
Hi Denis, thank you very much.
from image.
You are welcome :)
from image.
Related Issues (13)
- Background turn black in transparent png image HOT 2
- Background turn black in transparent png image after crop HOT 4
- Text alignment not working properly in a specific font HOT 1
- Gaussian Blur more than 2 passes HOT 4
- how to wordwrap text on images ? HOT 1
- Complete fork HOT 1
- PHP8 Can't crop image, image resource is undefined
- saveAs HOT 1
- Image 5.0.3 - Transparency background turn black HOT 1
- Update to last version of SimpleImage HOT 1
- Black box appears when trying to add an overlay HOT 7
- Black background at png images. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from image.