Is it possible with PHP GD to skew/distort images on both sides ?
I already check other question/solution but I really don't understand how to move all the corners of the image.
What I need is transform a flat image to a distort image moving all 4 corners, something like if you use Adobe Photoshop transform distortion function that allows to move single corner to a new position.
Is it possible ?
Many thanks in advance.
Bye
It can be done with the help of the QB extension.
In theory, it's possible to accomplish the same thing using just the built-in GD functions. It'd be agonizingly slow though.
I need to resize animated GIF in PHP without ImageMagick. I am using the latest GIFDecoder and GIFEncoder classes from PHPclasses. When I extract each frame from the GIF, I get blotches of transparent areas on all the frames but the first one, even though the GIF is not transparent at all. Even putting them back together does not work. I have tried other files but still have the same problem.
The original
How it turned out
Individual frames
If there are other solutions to resizing animated GIF please tell me, too. Thanks!
I would recomment using ImageMagick. It's way faster and more powerfull than any custom coded PHP class.
Please take a look at this thread. The top answer even offers an alternative solution, if you have no access to ImageMagick on your server.
I was wondering if anyone can teach me how to optimize an image when a user uploads? I would like to reduce the size quality of the image so when I show it on my page, it will load faster.
Thank you
Use GD or ImageMagick:
http://php.net/manual/en/book.image.php
http://php.net/manual/en/book.imagick.php
Take a look to http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php, examples are very easy to follow.
Added: I recomend you to keep the source image in its original size and create the resized one in a different folder.
Added: According to documentation, the function imagecopyresampled used by the class, does some kind of optimization:
_imagecopyresampled() copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity. _
Anyway, if you want more fine tune, as #mingos said, you can use ImageMagick, it's a bit harder, but there is a lot of samples here: http://www.imagemagick.org/Usage/
is there a good way to get the large image and resize it / slice it so the img will not loss her quilaty and aspect ratio in php?
10x
Yes.
Getting the image can be done with cURL for example. See http://de2.php.net/manual/en/book.curl.php
Resizing can be done with PHPs GD img functions http://de2.php.net/manual/en/book.image.php
or for better quality on resizing you can use ImageMagick or Cairo, which (at least ImageMagick definitely) require third party tools as well though. So only PHP will not be sufficient there. http://de2.php.net/manual/en/refs.utilspec.image.php
User of my site upload images which are used as avatars. I have set a upload limit size of 2 MB. At most places I only require thumbnails. But users upload images with far bigger resolutions. I store these files on my file-system.
How can i create thumbnails and store them instead of large sized files?
Depending on your installation / server setup, you have several possibilities.
You could use the GD library, and something like its imagecopyresized function
Or you could use the Imagick extension, and something like its thumbnailImage method.
I would say that I've quite never seen a server without GD installed -- for Imagick, its less likely to be installed by default :-(
Another solution might be to call the convert command-line utility (it comes with ImageMagick -- independantly of any PHP extension), using something like exec to call it.
Advantage, with that, would be that you wouldn't be limited by memory_limit, as the resizing would be performed by an external tool -- but, of course, it also means that your application will rely on an external tool, which is not always nice...
If necessary, there are plenty of tutorials about GD ; for instance, those might interest you :
How to create thumbnails with PHP and gd : it uses a batch process to generate thumbnails for many images -- which might be useful if you have to generate thumbnails for all images that you already have
Thumbnail generation with PHP tutorial : does some stuff not often seen, like create square thumbnails, by centering the orignal image and adding some background color.
You can use the GD module or the ImageMagick module to resize and shrink any uploaded images.
If you google around for something like "PHP image resizer", you'll find lots of examples. I tend to use GD, as I have an old bit of code kicking around that works just fine. Assuming you have a known uploaded jpeg image found at $srcImgPath, you could do something like the following, where $newWidth and $newHeight are the new sizes of image you want:
list($width, $height, $type) = getimagesize($srcImgPath);
$srcImg = imagecreatefromjpeg($srcImgPath);
if ($srcImg === false) return false;
$workImg = imagecreatetruecolor($newWidth,$newHeight);
imagecopyresampled($workImg,$srcImg,0,0,0,0,$newWidth,$newHeight,$width,$height);
imagejpeg($workImg,$newFilename,$quality);
Functionalize as appropriate, and be sure to specify the $quality. You can abstract this code out to handle gifs and pngs very easily as well.
Check out the gd library, specifically the imagecopyresized function
Just a quick note, if you go down the GD route, use imagecopyresampled, as it produces cleaner looking images. By that I mean it won't look as grainy and/or pixely.
Link to the PHP manual on the function: http://us2.php.net/manual/en/function.imagecopyresampled.php
I would recomend the timthumb.php script. it is rock solid.
http://www.darrenhoyt.com/2008/04/02/timthumb-php-script-released/
If you have Imagick installed in your PHP setup. Then there is a function that does this. Imagick::thumbnailImage()
If you don't have Imagick, then the GD library will come in handy. Since they have imagcopyresized()
Isn't Google AppEngine fitted with a subset of PIL? There is the 'resize' function that could be use... and best of all, you are getting a free quota!