sybio / imageworkshop Goto Github PK
View Code? Open in Web Editor NEWImageWorkshop is a PHP5.3+ library that helps you to manage images based on GD library
Home Page: http://phpimageworkshop.com/
License: Other
ImageWorkshop is a PHP5.3+ library that helps you to manage images based on GD library
Home Page: http://phpimageworkshop.com/
License: Other
Hi,
I have forked the repo and add some new function to it, when i try to push files it shows following error.
remote: error: object 11ea57ef17cf0a4ef0897724cca571fe3038f9ab:invalid author/co
mmitter line - missing space before date
remote: fatal: Error in object
error: unpack failed: index-pack abnormal exit
Can you please fix the issue with this commit?
Anyone else have this issue? I'm not using composer or any other auto loader.
I installed it in laravel 4. But i can't use it.
after i make something like:
$layer = PHPImageWorkshop\ImageWorkshop::initFromPath('/path/to/images/picture.jpg');
But system just response with: "Class 'App\Controllers\Management\PHPImageWorkshop\ImageWorkshop' not found"
Anyone know how to solve it ? Thank you
Hi
simply I can save my image by this:
$layer->save($dirPath, $filename, $createFolders, $backgroundColor, $imageQuality);
but how can I detect if uploading was successful?
is there any method to get that?
or I should do that myself?
thank you
Hello,
I can't display Kannada text in initTextLayer ( ex : ಟೆಸ್ಟ್).
It's encoded in utf-8.
How can I display india language?
Last version break initFromPath from URL.
ImageWorkshop.php 58-60
if (!file_exists($path)) {
throw new ImageWorkshopException(sprintf('File "%s" not exists.', $path), static::ERROR_IMAGE_NOT_FOUND);
}
hi all, i need to instantiate a textlayer but the method initTextLayer need a font file, is there a way to do without a font file?
thanks.
Currently not everything is tested by the assertions. For instance only the width and height are tested for the crop function. If the following code would do the same, the unit test would still succeed.
$layer->cropInPixel(50, 30, 0, 0, 'LT');
$layer->cropInPixel(50, 30, 20, 20, 'LT');
Instead of starting with a blank image as layer. You could start with an image with a 2D color gradient (like a color picker). Changing hue on the X-axis and saturation on the Y-axis.
After cropping you can check the four corner pixels to see if they have the expected color.
add this code to: ImageWorkshopLayer.php
too allow you to apply layer mask.
to use $layer_you_wish_to_apply_mask->applyalphamask($mask_layer);
/**
* Apply alpha layer mask.
* can be slower so best for images you don't need to remake for every user.
* @param layer $mask
*
* @author email [email protected]
*
*/
public function applyalphamask($mask){
$layerWidth = $this->width;
$layerHeight = $this->height;
$masktemp = clone $mask;
$masktemp->resizeInPixel($layerWidth, $layerHeight); // make $mask and $layer the same size.
$masktemp->applyFilter(IMG_FILTER_GRAYSCALE); //converts to greyscale if not greyscale;
$masktemp->applyFilter(IMG_FILTER_NEGATE);
$layerImg= $this->getImage();
$maskImg = $masktemp->getImage();
$imgtemp = imageCreateTrueColor($layerWidth,$layerHeight);
imagealphablending($imgtemp, false);
imagesavealpha($imgtemp, true);
for ($h=0; $h<$layerHeight; $h++){
for ($w=0; $w<$layerWidth; $w++){
$Lrgb = imagecolorat($layerImg, $w, $h);
$Lcolors = imagecolorsforindex($layerImg, $Lrgb);
$Mrgb = imagecolorat($maskImg, $w, $h);
$Mcolors = imagecolorsforindex($maskImg, $Mrgb);
$alpha = $Mcolors["red"]/255*127;
//$alpha = (int)( $alpha);
imagesetpixel($imgtemp,$w,$h,imagecolorallocatealpha($imgtemp,$Lcolors["red"],$Lcolors["green"],$Lcolors["blue"],$alpha));
}}
imagepng($imgtemp, realpath(dirname(__FILE__))."\imgtem.png");
//imagecopyresampled($imgtemp, $this->image, 0, 0, 0, 0, $this->width, $this->height, -$this->width, $this->height);
$this->image = $imgtemp;
}
Hello
is it possible to add an image to the GD image from remote URL?
(like initFromPath just from URL)
PHP Warning 'yii\base\ErrorException' with message 'imagealphablending() expects parameter 1 to be resource, boolean given' in \vendor\sybio\image-workshop\src\PHPImageWorkshop\Core\ImageWorkshopLayer.php:1097
The problem with the previous line, the line 1096.
The negative value is by setting the variable to false.
Correction:
To:
$imageRotated = imagerotate($this->image, -$degrees, -1);
From:
$imageRotated = imagerotate($this->image, -$degrees, imageColorAllocateAlpha($this->image, 0, 0, 0, 127));
Hello I am a learner and I have got things sorted out except when saving the image after resizing and adding a text layer it always creates new folders that already exists.
At the moment I have this script.
$dirPath = 'images/pos1';
$fileName = 'image.jpg';
$backgroundColor = 'ffffff';
$imageQuality = 95;
$layer->save($dirPath,$fileName,$backgroundColor,$imageQuality);
exit;
I already have the folder images and in there is a folder pos1.
I have tried under $fileName as I had$createFolders = true;
It says that it will create folders if they don't exists.
The folders exists and it creates them again. I have tried $createFolders=null; but got no where.
As you can see,by the above script, I have taken it out but still it creates the folders.
I want to put multiple images in the folders images/pos1.
I can not seem to find any information on that.
I have changed the folder names and the file name, from what they really are, but that is not important.
Thanks for your help in advance
Goodoh
Hi,
I have a project to do a greeting card application for a my website. I would like to know if there is a way to select the layer by mouse click and be able to do editing on that layer?
For example a user created 4 layer and then decide to do changes on the 2 layer.
Exiff data are lost after any transformation.
Add an option to keep these data.
Hi, I eve set the quality to 10, but there seem to be no effect on the image and the file size. No matter which quality ( 10 or 70 or 95) I tried, the images always look the same.
Any idea why?
Hi all i uploaded the PHPImageWorkshop into the root of my forum. then on the top of watermark.php file into inc\plugins folder i added this code but i get this error:
Parse error: syntax error, unexpected T_USE in /membri/merdronic/inc/plugins/watermark.php on line 183
Hii,
I am getting following error when uploading images...
Allowed memory size of 33554432 bytes exhausted (tried to allocate 4793473 bytes)
and it shows error on following code..
/home/almotar/public_html/vendor/sybio/image-workshop/src/PHPImageWorkshop/Core/ImageWorkshopLib.php public static function generateImage($width = 100, $height = 100, $color = 'ffffff', $opacity = 127) { $RGBColors = ImageWorkshopLib::convertHexToRGB($color); $image = imagecreatetruecolor($width, $height); imagesavealpha($image, true); $color = imagecolorallocatealpha($image, $RGBColors['R'], $RGBColors['G'], $RGBColors['B'], $opacity); imagefill($image, 0, 0, $color); return $image;
Help please...
Hello,
I have been going through the tutorial about adding watermarks and I seem to have found a problem.
When I attempt to add a watermark to a GIF image I just the text layer with the text on it and no image below that layer. At first I debugged my code but could not find a problem so then I tested with a JPG image and it worked.
So it appears that adding a text layer to a GIF image does not work. Is there something I am missing?
If i do not attempt to add the text layer and just save the image to a different filename then I can see the GIF image properly so it only when the layer is added to I get this issue.
Thanks, Russell
Hi guys,
btw, great work!
But I have one problem after using the function addLayerOnTop(). After saving the created image (as PNG) the background is always black. Here's the part of my code:
$sImagesPath = DOCUMENT_ROOT . '/img';
// background size 512x512
$backgroundLayer = PHPImageWorkshop\ImageWorkshop::initFromPath($sImagesPath.'/background.png');
// overlay size 120x45
$overlay = PHPImageWorkshop\ImageWorkshop::initFromPath($sImagesPath.'/overlay.png');
$backgroundLayer->addLayerOnTop($overlay, 10, 10, 'LT');
// saving image
$backgroundLayer->save($sImagesPath, 'generated_test.png', false, null, 100);
Is there a problem with the background image maybe (I used different images)?
Thanks for helping,
David
I wrote this to add Image Convolution matrix options to an image though I would share.
add this to \PHPImageWorkshop\Core\ImageWorkshopLayer.php
I put it just after apply Filter function.
public function applyImageConvolution($matrix, $div=0, $offset=0,$recursive=false){
if(is_string($matrix)){
$matrix = strtolower($matrix);
switch($matrix){
case "blur":
$matrix = array(array(1,1,1), array(1,.25,1), array(1,1,1));
$div = 8.25;
$offset = 0;
break;
case "emboss":
$matrix = array(array(2, 2, 2), array(2, 1, -2), array(-2, -2, -2));
$div = 0;
$offset = 127;
break;
case "gaussian blur" :
$matrix = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0));
$div = 16;
$offset = 0;
break;
case "sharpen" :
$Matrix = array(array(-1.2, -1.2, -1.2),array(-1.2, .4, -1.2),array(-1.2, -1.2, -1.2));
$div = array_sum(array_map('array_sum', $Matrix));
$offset = 0;
break;
}
}
if(is_array($matrix)){
imageconvolution($this->image, $matrix, $div, $offset);
}
if ($recursive) {
$layers = $this->layers;
foreach($layers as $layerId => $layer) {
$this->layers[$layerId]->applyImageConvolution($matrix, $div, $offset);
}
}
}
Hi, love this library, but I ran into a quite annoying issue:
http://i.imgur.com/fHlEqi1.jpg
As you can see, a few pixels are cut off on the outside.. The watermark looks ugly, making rotation almost unusable.
The image itself is perfectly round:
http://i.imgur.com/mmzSASg.png
I used a white background in the image itself just so you can understand better what the issue is here.
Any fix for this?
Hello,
I've been trying to make a web based GUI for this awesome class so we could actually make it work like Photoshop / Gimp on the fly but I've run into a problem.
I'm sending the data through a classical form but the Colors are always having a different value.
For example I'll give you the specific codes as the image etc loads up perfectly
Form code:
Output PHP code:
$myCopyrightColor = "'".$_POST["copyrightcolor1"]."'";
$myCopyright = ImageWorkshop::initTextLayer('© PHP Image Workshop', 'agency_fb.ttf', 11, $myCopyrightColor, 0);
This should be working without any problems but on the rendered picture ( same thing happens if I make it for a Background Color to use on a transparency ) instead of having a White copyright text, I'm having a Cyan color as a return.
Edit 1 :
If I set the color on the command itself as
$myCopyright = ImageWorkshop::initTextLayer('© PHP Image Workshop', 'agency_fb.ttf', 11, 'FFFFFF', 0);
It works perfectly, it doesn't work if the color value goes through a var only.
Any ideas?
Thanks in advance.
Hello, I've been trying to add an image upon a GIF image using your libraries.
However, it turns the gif image into some weird blue color.
I have tried to debug but I can't find what's wrong, I tried using getResult with a background color but it still didn't help.
I printed the frames as images and it seems that image #2 is the first image to get weird colors.
Here is the picture before:
http://i.imgur.com/M3bM7yP.gif
and after:
http://i.imgur.com/lyMu2P0.gif
Regards
I am all new to this but a willing leaner.
I search the forum and found this advice testing if installed.
To the point as I have un commented all require_once in all files in PHPImageWorkshop folder that I have in my lib folder.
test this script.
Got True
output:
test
Got false
Tested that file ImageWorkshop.php exists and got True
Then tried
output
fatal error: call to undefined function require_once()in C:\apachehtdocs\website\test.php on line 3
then tried
And I got the same fatal error as before
At other times doing something a little different
fatal error :require_once():failed opening required"PHPImageWorkshop/ImageWorkshop.php'(include_path='.;C:apache\php\PEAR')in C:\apache\htdocs\website\test.php on line 3
Your help would be very appreciated.
When I down loaded the zip ImageWorkshop_master only recently it is on my download file and I have unzipped and have the file PHPImageWorkshop in my lib file as it says inn the installations etc. I am using xampp with with php5.5.0 if that may be of importance
Thanks Goodoh
I want install this app in datalife engine. Datalife have function watermark but I can install this app because in datalife do not working watermark for gif animation and I really need this feature.
Sorry for this question because I am not pro in PHP and I can not do it.
Hi, I am a beginner using php, I am getting no image display. I did the test script and it seems that everything is OK, but actually I am doing something wrong because it is not working. This is my code.
'; var_dump(class_exists('PHPImageWorkshop\ImageWorkshop')); echo'I am getting a thumbnail with no image. If I comment the last 3 lines this is the result.
bool(true)
bool(true)
string(40) "PHPImageWorkshop\Core\ImageWorkshopLayer" 1000221
Can someone help? Tell me what I am doing wrong.
composer file
{
"require": {
"php": ">=5.3.0",
"sybio/image-workshop": "2.0.*"
}
}
index.php
<?php
$background = PHPImageWorkshop\ImageWorkshop::initFromPath(__DIR__.'/img/aboutus.png');
echo $background->getWidth();
Any help will be appreciated where i am wrong
I need to validate that the file was saved in the folder.
The current result is null.
$newImage = $image->save($dir, $filename);
if($newImage){
//save the information in the database
}
Is it possible?
Hii,
Please explain How to Install and use Imageworkshop in Laravel 4?
Thanks.
I used tutorial but I don't understand, why my code does not work and it does not display any error!
use PHPImageWorkshop\ImageWorkshop;
use GifFrameExtractor\GifFrameExtractor as GifFrameExtractor;
require_once('src/PHPImageWorkshop/ImageWorkshop.php');
require_once('GifCreator-master/src/GifCreator/GifCreator.php');
require_once('GifFrameExtractor-master/src/GifFrameExtractor/GifFrameExtractor.php');
$gifPath = '/folder/images/pic.gif';
if (GifFrameExtractor::isAnimatedGif($gifPath)) {
$gfe = new GifFrameExtractor();
$frames = $gfe->extract($gifPath);
$watermarkLayer = ImageWorkshop::initFromPath('/folder/images/watermark.jpg');
$retouchedFrames = array();
foreach ($frames as $frame) {
$frameLayer = ImageWorkshop::initFromResourceVar($frame['image']);
$frameLayer->resizeInPixel(350, null, true);
$frameLayer->addLayerOnTop($watermark, 20, 20, 'LB');
$retouchedFrames[] = $frameLayer->getResult();
}
$gc = new GifCreator();
$gc->create($retouchedFrames, $gfe->getFrameDurations(), 0);
file_put_contents('/folder/images/newgif.gif', $gc->getGif());
}
or this is my all folders and files.
https://www.dropbox.com/s/6v4tfq7mv3gm2q9/gif.rar
imagecopyresized gives poor quality images when scaling down from big ones.
Please, use imagecopyresampled instead in resizeBackground function.
You need to tag versions as you are creating them, otherwise packagist will not know you've released a new version.
I am currently implementing PHP Image Workshop like this:
"sybio/image-workshop" : "*",
I want to be implementing it like this:
"sybio/image-workshop" : "1.3.*",
This would mean that I can build my application around a specific version (while allowing minor patches) and would also mean that I don't get 2.0 forced down my throat when you push a few new commits.
This has caused errors on my live site. To get around it I have forked the repo, hard pushed to 6288ef2 and referenced the commit in my repo.
Please, please implement tags.
Actually the library use PHP GD extension for image manipulation.
But with PHP >= 5.5, there is some issues with this extension (particularly with rotations). It could be very interesting to have other providers (like ImageMagick for example) and let the developer choose what he want to use.
Hi guys,
i updated the latest (2.0.7) via composer. my working code which contains ImageWorkshop::initFromPath get broke and gives 500 error. I tried debug it but phpstorm just stops the debug and gives nothing. Any idea?
Hi.
I'm trayng to install with Autoload:
//index.php
use PHPImageWorkshop\ImageWorkshop;
require_once(DIR.'/include/i_autoload.php');
//include/i_autoload.php
require_once(DIR.'/PHPImageWorkshop/Exception/ImageWorkshopBaseException.php');
require_once(DIR.'/PHPImageWorkshop/Exception/ImageWorkshopException.php');
require_once(DIR.'/PHPImageWorkshop/Core/Exception/ImageWorkshopLayerException.php');
require_once(DIR.'/PHPImageWorkshop/Core/ImageWorkshopLib.php');
require_once(DIR.'/PHPImageWorkshop/Core/ImageWorkshopLayer.php');
require_once(DIR.'/PHPImageWorkshop/ImageWorkshop.php');
//include/photo.php
$Avatar = ImageWorkshop::initFromPath('uploads/' . $_SESSION["DataUsrLogin"]["photo"]);
And the site show me this:
Fatal error: Class 'ImageWorkshop' not found in include\photo.php on line XX
What I missed?
Thanks
I am trying to use you lib to download bulk images from remote urls to my server. but it seems slow and got mostly php script gets stop after 20 (more or less) downloads. sometimes, i get execution time out. in addition to that, your lib breaks if image extension is jpe.
can you please suggest me the optimal usage for bulk image download and how to deal with jpe image extension?
Thanks
Actually tests are broken with PHP >= 5.5
PHP 5.3 is dead and PHP 5.4 only have security fix and will be deprecated in less than 1 year.
It will become essential to ensure compatibility with modern PHP versions.
Hi,
I am parsing html document to extract image urls and store them in DB. then i wrote php function to get those urls then do image downloads to my local server.
i want to use your library to create thumbs from the downloaded images folder, for that i have wrote another function to read image names from DB and submit those names to your library to create thumbs then mark image name as thumb created in DB.
my problem here is that your library gets break if the image url does exist in DB but not in the downloaded folder.
Any suggestion please?
I cant find the variable, what can transform text to UPPERCASE in text layer. Can you add this function?
Hi,
It works very good on my localhost.
On the Live Server i get:
Fatal error: Uncaught PHPImageWorkshop\Exception\ImageWorkshopBaseException: [2]: You must give a php image var to initialize a layer. thrown in /inc/PHPImageWorkshop/Core/ImageWorkshopLayer.php on line 142
Whats the Problem?
i was download your sample file ImageWorkshopTest.php it show error
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in C:\xampp\htdocs\gdimgtests\tests\ImageWorkshopTest.php on line 19
Hi Sybio
Firstable thanks for this very usefull class :) !
Im trying to initialize a image uploaded from a - Wordpress - form.
resizeInPixel(null, 200, true); $giflayer->save(__DIR__."/images/edited", "closing_edited.png", true, null, 95); ?>I tried to create a folder named "tmp" in "wp-content\themes\my_theme", but still not working ... this fatal error appear again and again : " No such file found at "" thrown in (etc.) "
What did I do wrong ?
Could you explain to me what do you mean by "and if you can't, first save the file and then open it as a layer from its saved path." ?
Je suis vraiment débutant en php, désolé si la réponse est évidente !
En te remerciant d'avance ;)
Teksi
Been trying out this library and when I try to change the opacity of a watermark layer I get timeouts in the imageCopyMergeAlpha
function.
/**
* Watermarks an image
*
* @param $orginalImage
* @param $destinationImage
*
* @return string
*/
function watermarkImage($orginalImage, $destinationImage)
{
// watermark size
$image = \PHPImageWorkshop\ImageWorkshop::initFromPath($orginalImage);
$watermarklayer = PHPImageWorkshop\ImageWorkshop::initFromPath('/img/overlay_logo.png');
$watermarklayer->opacity(50);
$watermarklayer->resizeInPixel(($image->getWidth() / 2), ($image->getHeight() / 2), true);
$path = pathinfo($destinationImage);
$image->addLayerOnTop($watermarklayer, 0, 0, 'MM');
$image->save($path['dirname'], $path['basename'], true, null, 100);
// return the watermark image
return $destinationImage;
};
They appear at line 228, 229, 233, 259 and 260. I'm not sure what causes the maximum execution time exception to be thrown. It does not seem to have a real reason for it.
Using the last released version. php -i
info down here:
$ php -i
phpinfo()
PHP Version => 5.6.7-1+deb.sury.org~trusty+1
gd
GD Support => enabled
GD headers Version => 2.1.1-dev
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.5.2
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 8
PNG Support => enabled
libPNG Version => 1.2.50
WBMP Support => enabled
XPM Support => enabled
libXpm Version => 30411
XBM Support => enabled
WebP Support => enabled
Directive => Local Value => Master Value
gd.jpeg_ignore_warning => 0 => 0
Hi,
I would like to know how can i import an image from an external url.
Thanks,
Giacomo
I would like to know if there is a way to create layer by a drag and drop function.The images are saved locally on the hard drive.
If someone has a demo it would be fantastic.
Hi, it would be of great help to me if you published The list of methods here.
http://phpimageworkshop.com/doc/21/list-of-the-methods.html
Thanks for a really great library!
I have raised this problem before.
I have in a test file.
I'm getting error undefined function
Is it something to do with the path.
I also have a script folder and in there I have a file myscript.js.
An external javascript.
That does not work but does if not in the script folder.
I don't understand why as it should but reading in forum I saw where and to the point
lib
Add ImageWorkshop.php in lib you now have lib/ImageWorkshop.php
Images folder give 777 rights to allow the script to create images inside.
Hi,
I didn't see any option of adjusting letter spacing(font kerning). This is a great fun library to use and it's the one thing that is missing for the projects I am working on. Is there a workaround to this?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.