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
Related
I have to check few JPEG files for quality level and give to every file corresponding quality mark. Then I must be able to choose better image by this mark.
How to decide about visual image quality?
I'm dealing with photographs. Image dimensions and even compression ratio cannot indicate
visual quality of of the image. For example, if you enlarge the image and save it with bigger quality the visual quality will be reduced...
The code is in PHP.
Any advises will be very thankful!
If you have access to the original image then SSIM is one of the better methods to do this. It'd be pretty slow to do in pure PHP, but if you can execute shell commands, check DSSIM tool (you'll need to adapt it to load JPEGs instead of PNGs).
ImageMagick has compare command that can return Mean Square Error/PSNR of the image (compared to original), but these measurements only check per-pixel differences, so they are a poor way measure distortion caused by blockyness and ringing of JPEG compression.
Users on my site upload images of various dimensions. Some might be huge some might be small so resizing to a default image might work but small images being resized would look ugly. Is there anything i can do to resize all images to one size and make the quality clear without making it look crappy?
You will not be able to make small images "High Definition". No image can be scaled to a larger size without loosing clarity (with the exception of vector graphics, but I'm guessing that isn't what you're working with). You can, however, resize larger graphics into smaller ones.
Try phpThumb for an excellent image manipulation library, or see JohnPS's answer for a good solution for re-sizing larger images.
There is a PHP PEAR package Image_Transform that you can install to do basic resizing of images.
This package includes a function fit that will shrink an image to fit inside a box (width and height), but leave it the same size if it's already small enough. See scaling function docs.
I'am using PHP GD to copy an image (watermark) on another image.
Unfortunately the quality of the watermark is terrible.
I'm using quality 100% as the attribute, but it doesn't help.
Have you guys know any good way to increase the quality?
Regards.
A 90% quality should give you the exact same results and decrease the file size by half (on JPEG, OFC).
Try using ImageCopyResampled() instead of ImageCopyResize(), other than that I don't think you can do anything else with GD alone, maybe Imagick has some other tricks.
Are you using any transparency, or is it just a solid square. What exactly looks bad about the quality? The edges, the whole thing?
I like to use a 24bit transparent PNG for the watermark, and imagemagick to do the overlay, you get a lot of control over the final product that way.
Lots of possibilities for watermark with imagemagick:
http://www.imagemagick.org/Usage/annotating/
So I'm in the middle of working on a website that deals with photographs. A user uploads their original photograph and GD library creates a smaller sized image of the same photo. However, when comparing a manually sized down image with the GD one, the GD image seems to lose quite a bit of color quality like it had been slightly desaturated. Any alternate suggestions or ways to improve this?
Thanks!
I'd advice using imagemagick for handling anything serious about photos.
besides quality, you'll find using imagick functions like more convenient
Imagick::cropThumbnailImage()
Imagick::thumbnailImage()
Use imagecopyresampled instead of imagecopyresized. It gives much better quality. Also, try NOT to use GIF images as output.
Wow, the answer is imagemagick. Easier to use and maintains the full photograph quality!
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!