How would I go about cropping an image automatically on the server? - php

Like at Digg.com, I want to get members' pictures cropped for an avatar use. Please show me how to do this in PHP.

Here is a free script that does it using either GD or Imagick (Imagick is faster so I would use that):
Crop & Resize with JavaScript, PHP, and ImageMagick
From near the top of the page linked above:
Update: A new version of this example
and demonstration has been released.
Version 1.1 includes a GD version of
the script as well as a number of
functional improvements worth checking
out.

Related

Magento is Stripping all EXIF Data When Uploaded

Because this shop is an eCommerce it helps a lot to have picture with EXIF data, but for some reason when the images with EXIF data is uploaded magento seems to strip all of that info from the image and only show the bare image in the front end.!
can anyone tell me why this is happening and how we can avoid it?
Cheer!
It's a side effect of using the GD2 library for resizing.
lib/Varien/Image/Adapter/GD2.php
See if there's a module out there that uses ImageMagick if you want to preserve EXIF
Quote from PHP website on using GD:
When developing code to resize images, it is best not to use GD. When
using the current GD methodologies, you are reading content from an
image and manipulating it. By then writing that content to a brand
new file, you are losing the EXIF data.
For purposes when you want to retain EXIF data, it is recommended that
you compile in and use the PECL Imagemagick extension. It has great
resizing methods built right in and the EXIF data is retained.
ImageMagick isn't used because of issues with server loading.

Where can I find comprehensive image manipulation library information?

I've spent a lot of time Googling and searching SO for information on image manipulation libraries with little success. Please direct me if this has been answered before and I just can't find it.
Basically I'm trying to resize an arbitrarily sized image to a couple of smaller thumbnail images, say 400px wide and 200px wide while maintaining the original aspect ratio. The original image is being uploaded via php (linux) and I've found that I can use Cairo, GD, GMagick, or ImageMagick but I've been unable to find comprehensive data on which is better suited for image manipulation. I have found comparisons for image creation, but that's functionality I won't be using.
I also have the option of uploading via php then performing the image manipulation via another method (perl/python/etc, for example) if that proves better suited.
Any pointers in the right direction are appreciated. Quality is my primary motivation followed by output image file size then library performance.
GD and ImageMagick are your best bets, so get some representative images and run some tests using:
imagecopyresampled() for GD
Imagick::thumbnailImage() for ImageMagick
Imagick::resizeImage() if you want more control and to try a few filter constants.
Resizing images in PHP with GD and Imagick has some code samples to get you going.
Compare them visually and by filesize. If there's no obvious winner, then run some benchmarks based on your expected needs. How to benchmark efficiency of PHP script is a good reference point.
Also take a look at:
Choosing between Imagemagick & GD for thumbnail creation
Should I use ImageMagick or GD2 with ImageAPI in Drupal?

How to server-side resize images in PHP5 without external libraries?

Background: For an university project I have to use PHP5 to create a web application that also deals with images. I'm not allowed to use any external APIs, frameworks or AJAX.
Is there a native function to resize images in PHP5?
(I know a can specify both width and height for an img tag, but that resizing is done on the client. I'd rather save downsized images on the server.)
The GD library has been bundled with PHP since 4.3, and will do what you want: http://uk.php.net/manual/en/book.image.php. You'll probably want something like imagecopyresampled.
Most PHP installations come bundled with the GD library. In fact, I've yet to come across a PHP installation that doesn't have GD bundled.

tint images without imagemagick

I have an upload form for images that once uploaded are then displayed automatically and randomly on a website. I would like to apply a colour tint to the images before they are saved, at the very least one green but preferably various colour tints which are saved in relevant folders /green/ /red/ /blue/ etc. so I can make skins for the site.
My hosting package doesn't allow me to install imagemagick so I'm looking for a way to achieve these results in html css and php preferably, as that's where my limited knowledge lies, but if that's not possible I will consider other options.
is gdlib enabled?
or you use aviary or one of their apis http://developers.aviary.com/filter-list
http://developers.aviary.com/
Update: as Aviary is no more offering this service as before but here are some more good solutions:
take a look at Pixastic (coloradjust)
https://github.com/jseidelin/pixastic
http://www.pixastic.com/lib/docs/actions/coloradjust/
or PaintbrushJS (colour tint)
https://github.com/mezzoblue/PaintbrushJS
http://mezzoblue.github.com/PaintbrushJS/demo/
If the PHP on your hosting package is compiled with the GD library you could use that instead. imagefilter

creating a box with an image

I'd like to take an image and turn the corners over to make a box (like a canvas painting)
i have gd library, imagemagick installed on the server and imagick php extension installed.
is it possible? any help appreciated
turn the corners over
You're gonna need to explain this a little better. You can overlay a frame onto an image with the GD functions. Check out imagecopymerge()

Categories