sprain / class.images.php Goto Github PK
View Code? Open in Web Editor NEWA PHP class to handle image manipulation
A PHP class to handle image manipulation
Currently, when cropping a image, you always start at 0|0. Would be great if you could add the additional option to crop a different area.
Something like:
public function resize(
$max_width,
$max_height,
$method="fit",
$cropAreaLeftRight="c",
$cropAreaBottomTop="c",
$jpgQuality=75,
$dst_x=0,
$dst_y=0
) {
You could also check if is_numeric($cropAreaLeftRight) and is_numeric($cropAreaBottomTop) and when they are both numeric use those values for positioning the cropping area.
I used the #2 demo, and after rotating my png files are saved as jpg.
whats wrong?
am using pagodabox as hosting with GD entension enabled & i get this error:
Call to undefined function ImageCreateTrueColor() in /path/to/file/images.class.php on line 248
i think it should be in lower case.
http://php.net/manual/en/function.imagecreatetruecolor.php
See test/pngTest.php. If rotated 90 degrees, you see crazy stuff.
We discussed this on your HP some time ago. I maybe have a solution. Try this code:
public function writeWatermark($opacity=50, $marginH=0, $marginV=0, $positionWatermarkLeftRight="c", $positionWatermarkTopBottom="c"){
//Watermark
list($image_create_func, $image_save_func) = $this->Watermark->getFunctionNames();
$watermark = $image_create_func($this->Watermark->getImage());
//get base image
list($image_create_func, $image_save_func) = $this->getFunctionNames();
$baseImage = $image_create_func($this->image);
imagealphablending($baseImage, true);
imagesavealpha($baseImage, true);
imagealphablending($watermark, true);
imagesavealpha($watermark, true);
// resize the watermark to fit original image size
//imagecopy( $baseImage, $watermark, 0, 0, 0, 0, imagesx($watermark), imagesy($watermark));
imagecopyresampled( $baseImage, $watermark, 0, 0, 0, 0, imagesx($baseImage), imagesy($baseImage), imagesx($watermark), imagesy($watermark));
//Set image
if(!$image_save_func($baseImage, $this->tmpfile)){
throw new Exception("Cannot save file ".$this->tmpfile);
}//if
//Set new main image
$this->setNewMainImage($this->tmpfile);
//Free memory!
imagedestroy($baseImage);
unset($Watermark);
}//function
I tried this with PNG and JPG as base image and PNG as watermark image. It also resizes the watermark to fit the base image size. I've still got to do some testing, but maybe you'd like to check this meanwhile.
at writeWatermark function, with current stock function watermark image has bad quality, but base image is good. This is fix:
instead
//Set image
if(!$image_save_func($baseImage, $this->tmpfile)){
throw new Exception("Cannot save file ".$this->tmpfile);
}
I replaced with
//Set image
$img_quality = '';
if($image_save_func == "ImageJPEG"){ $img_quality = 100; }
if($image_save_func == 'ImagePNG'){ $img_quality = 9; }
if(!$image_save_func($baseImage, $this->tmpfile, $img_quality)){
throw new Exception("Cannot save file ".$this->tmpfile);
}
Now watermark is good quality. Only I dont know how will it work with gif
Heute habe ich ein Problem mit transparenten PNGs entdeckt – nach dem Bearbeiten mit deiner Klasse hatten die Bilder alle einen schwarzen Hintergrund. Wahrscheinlich ist das zwar nicht der perfekte Bugfix, aber durch den folgenden Block in Zeile 248 (im “//Let’s get it on, create image!” Block nach der ersten Zeile eingefügt) wird das Problem gelöst:
if ($image_save_func == “ImagePNG”) {
imagesavealpha($imageC, true);
$trans_colour = imagecolorallocatealpha($imageC, 0, 0, 0, 127);
imagefill($imageC, 0, 0, $trans_colour);
}
I just changed the line 235 to this: $exif = @exif_read_data($this->image);
But it is not the best solution.
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.