PHP Thumbnail Class - php

I am looking for a solid PHP thumbnail generating class. Does anyone know any good ones that are open-source?
I could write one, but I really don't want to. The one thing I hate most about PHP is manipulating images with GD and Imagemagick.
Does anyone have any suggestions?

Use phpThumb(). Its a script that internally uses GD library and/or ImageMagick (whichever is available and whichever it thinks is best for the job) to perform basic image manipulation tasks, including thumbnail generation and square thumbnail generation.
You can use it like this:
<!-- best fit -->
<img src="/phpThumb/phpThumb.php?src=/path/to/image.jpg&w=64&h=64">
<!-- crop fit (square thumbnails) -->
<img src="/phpThumb/phpThumb.php?src=/path/to/image.jpg&w=64&h=64&zc=1">
It has built in caching engine so second time a browser requests the above image it is served from its own cache instead of re-generating the thumbnail every time. Though, you may want to spend an hour or so configuring it.

use class.upload.php
see this link for details may be its help you more
http://www.verot.net/php_class_upload_samples.htm

Generating a thumbnail requires so little code that it is a "simple example" of the GD library's resizing functions in the manual:
http://php.net/manual/en/function.imagecopyresampled.php
Just copy and paste.

Related

Place the top left corner of an image on a specific pixel with imagemagick

I have an image of NxN size and an image of MxM, with N>M. I want to place the second on top of the first, but I want to do it on a specific pixel e.g.(10,15)
I installed imagemagick and start playing with it cli (planning to try with php later), but I could not find if there is something that I could use for this purpose or if it is possible by combining some commands.
So my question(s):
Is something like this possible with imagemagick?
If yes, how could I achieve it in command line imagemagick?
If yes, how could I achieve it with imagemagick in php?
Expanding on my comment, I think php gd would be a good fit for this. PHP gd is better integrated into php and works better in my opinion. I use it for a host of things (resizing thumbnails most notably). Your question seems very similar to placing a watermark on an image, ie one image is place on top of another and it is exported as a single raster image. Here's a quick example for creating this watermark:
http://www.sitepoint.com/watermark-images-php/
This example exports it directly to the browser, but it can be easily modified to save the image locally to your file system. Enjoy!

PHP or Javascript or other - Draw simple shapes onto images?

I basically have an image of a world map and i would like to place a pin image at a specified pixel co-ordinate ontop of this world map image.
It's for a website, so ideally the solution should be in PHP or Javascript (i'm avoiding Java and Flash as i want it to be as simple as possible).
I had a look at the processing.js library but it is way to big and bloated for just performing this simple task.
Is there a pre-existing Javascript function which will allow me to do this? Or a more simple javascript library that i can use? (processing.js was a bit too advanced for me, i couldnt get it working lol)
In terms of a PHP solution, i would prefer taking the load off the server and onto the client for this task, but i would still like to hear methods for doing it in PHP if they are suitable.
Thanks!
the easiest way to do this is to put pin image over map image and set them position in css like this:
<div style="position:relative">
<img src="map.png" style="position:absolute; top:0px; left:0px; z-index:0"/>
<img src="pin.png" style="position:absolute; top:50px; left:30px; z-index:1"/>
</div>
I suggest using the GD Library Extension for PHP. From this you can manipulate images and produce a new output. Then you can either cache it somewhere and redirect the user, or serve the image by tweaking the output headers and writing the binary data out to stdout.
header("Content-Type: image/jpeg");
As Aren mentioned, GD is good for this.
However, an alternative to the GD Library is Imagemagick. This gentle introduction is very helpful.
ImageMagick® is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.
Do you really have to have that 'pin image' in the image itself? Simple HTML & CSS (absolute positioning) would solve this very nicely with practically no load for everyone involved, with the only downside the image is not saveable with the overlaying image included.

Image compression and thumbnail creation for PHP

I need some PHP classes that deal with image processing in a good manner. I have made a thumbnail creator myself but the end result quality is just horrible.
Is it also possible to let PHP convert and save all images to one type. For example take an image(jpg,png,gif), compress it, resize it, and save as png.
Can anyone recommend some good classes for this.
Check out https://github.com/avalanche123/Imagine, given you use PHP 5.3, it will solve most of your image processing needs
You can take a look at this one
http://shiftingpixel.com/2008/03/03/smart-image-resizer/
You can look into the php gd library, or imageMagick, which has bindings for php.
If you have access to command-line i'd recommend image magic. The comman-line version has the advantage that it includes several features for batch processing.

Using PHP to recreate something similar to VistaPrint / CafePress / Zazzle. Any Ideas?

I am working on a website in which the client wishes to have users upload background images to a printable design, crop to size, add text. Do this to multiple pages then generate a pdf of the 'book'
I am running into the following issues/questions and just need to see where I can start
Are there any PHP developer packages that can do something similar. I have seen jquery crop tools but something also for adding text to an image?
How would I keep the resolution up? If the final cropped with text image needs to be 150dpi, when cropping I am guessing I would have them working on a 72dpi image, then somehow apply the crop and changes to the large image?
If the resolution issue wasn't a big deal I would go about it this way:
Simple image upload
Use jquery to crop photo to correct dimensions
Mess around with gdlibrary and imagettftext() to get the text onto an image (page)
Use something like FPDF to create a pdf from each 'page'
Is this the right way to go about it and any thoughts on the resolution issue. Thank you for any help!
Your primary tool should be ImageMagick. ImageMagick can do the cropping, resizing, scaling, overlay text or graphics, combining images, and apply special effects. A big advantage of using a separate tool instead of PHP's image manipulation tools is that you can do the same transforms in batch through other mechanisms, or even hand the work over to another server to keep the website more responsive. And if you do want to integrate it tightly into the website, you can use the MagickWand For PHP interface.
Cropping does not change DPI, only the dimensions of the image. Scaling, on the other hand, changed both.
You should take a look at Gallery, a GPLed program with some of the functionality you're looking for, and written in PHP.
domPDF is a good tool for converting HTML to a PDF. this way you can use the image they upload as a background image, then put the text over it in any standard HTML tag.
As far as the resolution/dpi issue goes, I'm not sure if there is much you can do outside of changing the size of the image. I would recommend looking into This PHP Library, which has a lot of good tools for manipulating images.
I think with a combination of these tools, you'll be able to create HTML that can make a PDF that's fit to print, and use that.

How to resize linked images dynamically in PHP?

On my site I have given an option to user to choose thier profile image
Type link of an image
Image is a url link, and first I want it to resize to 400x300 (image's original size doesn't matter), and then display it on my web page.
Something like below:
<img src="http://mywebsite.com/resize.php?image=http://someotherurl.com/upload/image2.jpg&width=400&height=300" />
anyone knows this kind of script, please tell me how to solve this issue.
Thanks
A recent post:
https://stackoverflow.com/questions/1302464/php-image-resize-my-upload-script
has some code and comments that may give you some pointers. Otherwise may I suggest
http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php.
Good luck!
If you have the GD extenstion, you can use imagecopyresampled (the documentation also features some examples). However, if the image to be resized is large and there is a low memory limit on your server, you may run out of memory.
I don't have ready to use source code, but it should look like:
Load image pointed by image parameter into object of ImageMagick (or other graphics library).
Resize it.
Send content to output stream.
Optionally you could:
Check if loaded file is image (plus other validation checks).
Save resized image on disk and serve it from disk next time (if you do it often).
Check docs of you favorite graphics library used in PHP for details.
Good luck!
Use the Class called - class.upload.php.
Find it at: PHP Classes
We use it at all times in many of our work.
The name is deceptive but actually it is an uploader as well as image processor. It has a very big list of functionality for resizing images, adding text to images, converting formats, etc. etc.
There is sample code which shows how to read an Image from server, modify it and finally send it directly to browser without having to create a temp file on server.
HTH

Categories