Require a PHP Image Resizer/Cropping Script - php

I am grabbing links to images and need to convert them on the fly to 72x108 to display on a website. The source images come from various resolutions, so cropping is required.
I know a moderate level of PHP so I can probably make something work for my needs, but was hoping for something that could be called by a url request. EG: mysite.com/thumbnail.php?src=http://anothersite.com/image.jpg&w=72&h=108
That would be ideal, it needs to support jpg/png.
Thanks in advance!

Here is a really handy script for processing and uploading images that's been a top google result for forever. I used it years ago and it was really easy to implement. Looks like it was just updated a couple weeks ago too :)
http://www.verot.net/php_class_upload.htm
This may be overkill, but if you check out the examples you can see there's a lot you can do with it. If you don't use it for this project, it might be worthwhile to try out for the next one.

just read the image from the url with file_get_contents or using curl and use the php gd library to resize and crop the image as per your needs.
Go through the following links for more info:
http://php.net/manual/en/function.file-get-contents.php
http://php.net/manual/en/book.image.php
http://davidwalsh.name/download-urls-content-php-curl

Related

Dynamic PHP images

I was looking through posts about modifying/packaging images in PHP and can't seem to find anything. What I'm trying to do is have an image template that I can modify by $_GETting a variable.
For instance: http://foo.bar/image.php?content=Monday
If we were then to wrap the above in an tag, it would show as "You have been invited to a party on Monday!" (Something to that effect)
Basically:
Set template
One or two words changed on said template
Auto-resize to fit a page
If anyone could provide a link to a library that does this, or provide a code example, that would be great.
Might want to take at this page from PHP.net -> http://us3.php.net/manual/en/image.examples-png.php
You can generate images in PHP using Cairo, ImageMagick or GD. There's a wealth of documentation on PHP's site: http://www.php.net/manual/en/refs.utilspec.image.php
Note that not every API/function library is available on every system. I remember even a few years ago that ImageMagick and GD were hard to get working on non-Linux systems. I don't know how it is today though.

Suggest a good image upload-and-crop tool

I'd like to know which up-and-crop tools you suggest to me. I tried couple of scripts like JCrop but I always get stack with some type of format like bmp. I either can't upload or I can upload but can't crop. If you use (or know) one that works well with different formats, then please just give me its name and I'll be strongly appreciated!
Well, i dont know much about JCrop but you can build it up with several tools.
I think image processing kind of works should be done on server side.
There is a good OOP Library called Imagine. It's mostly based on Python's Imaging Library which is awesome and has decent documentation. And this is its crop functions documentation.
On client side you can use some kind of image area selection tool to let the user determine desired area to crop. imgAreaSelect is good to go. Then you can send crop area to php by JQuery's post function or any other way.
It's amassing that in all this time this haven't got any other answers, I hope this helps.
Like stated in the other answer you should combine a few tools to solve each part of the problem.
To let the user select the cropping area:
If you don't like jCrop you can try Guillotine. It's very lightweight, easy to set up and allows to crop, zoom and rotate images. It has touch support and it's responsive (fluid).
Keep in mind that you can't display image types that the browser doesn't support, but you can convert them in step 3.
To upload the images:
For most cases, once you have the cropping area, with a simple file input will suffice.
Now, if you want to upload files asynchronously check out
this
for a quick and easy set up or this
for a more complex solution.
To actually crop and process the image:
Once uploaded you can crop, convert and process the images on the server, ImageMagick is a great tool for this. It's Open Source and many languages have wrappers for it.
You've tagged the question with PHP so here is a PHP wrapper for ImageMagick.

php mosaic script

I'm using a script that I downloaded from google code to dynamically generate mosaic images with the GD library. The script seems a bit convoluted. I've messed around with it quite a bit, but I'm sort of confused since it's written in German and I don't speak deutsch. I know that in order for it to work, I need to have 121 different images. But, I'm not sure if they needs to be in the directory or in mysql. Does anyone have a clue as to how to use this? Or does anyone have some suggestions for a better script for generating mosaic images with the php GD library?
The script can be found here: http://code.google.com/p/phpmosaic/
Thanks,
Lance
The images you like to use as thumbnails have to be inside a directory. You must add them to the db using the methods
phpMosaicImageParser::parseImageFolder() or
phpMosaicImageParser::parseImage()
However: there is no fix number of required thumbnails, it will depend on the SourceImage and the used options how much thumbnails you'll need at least.

Php code for getting the first frame of a video(flv)

I have using flow player for playing my .flv videos.How i can create a thumbnail from the first frame.Is their any inbuilt Php code for doing this one.
Thanks in advance.
The only way I know of is using FFMPEG. I have never used this script, but looking at it seems to be what you need, and may need some tweaking.
http://www.longtailvideo.com/support/forums/jw-player/setup-issues-and-embedding/447/show-first-frame-as-preview-image
EDIT
To get the image / display it you would just use the html code:
<img src="http://my.domain.com/path-to-file/ffmpeg_image.php?file=video.flv&time=00:00:00&browser=false" />
From what I gathered from that script. But of course, it would probably be better to, when you upload the video, run that and generate a "cache" of the image so that whole process does not have to run for each call.
Not exactly what you are looking for but a good way of showing the first frame of a video in flowplayer is to set autobuffering to true:
clip: {
autoPlay: false,
autoBuffering: true,
}
This will load the video (wich might be very bad for you).
To do it yourself you need something like ffmpeg installed on your system. if it is installed check this out.
Hmm, some guy on the forums needed something similar and I tried to help him, idiot-proof style. Check out the last post on this thread. I hope it helps.
link

Creating a file progress bar in PHP

Does anyone know of any methods to create a file upload progress bar in PHP? I have often heard that it's impossible.
I have one idea, but not sure if it would work: have a normal file upload, but instead submit to an iframe. When this is submitted, store the file information (size and temp location) in the session. At the same time, start an AJAX call to every say 10 seconds to check the size of the file compared to the size stored in the session. This would return the size to the AJAX and then a progress bar would be sized and maybe display the uploaded size to the user.
Thoughts?
You're pretty much figured out how to do it. The main problem is you usually don't have access to the size of the uploaded file until it's done uploading.
There are workarounds for this:
Enabling APC, you to access this information if you include a field called "APC_UPLOAD_PROGRESS" and use apc_fetch() for retrieving a cache entry with the status.
There's also a plugin called uploadprogress but it's not very well documented and doesn't work on Windows (last I checked anyway).
An alternative is to use Flash for doing it. See scripts like FancyUpload.
Before APC came along I had to write a CGI script in C that wrote information to a text file. APC seems like a much better way to do it now though.
Hope this helps.
So far, the most common way of doing this is SWFUpload: http://www.swfupload.org/
However, it is possible with pure PHP, just very difficult and very experimental. I'll see if I can find the link.
Edit:
According to comments on php.net, as of 5.2 there is a hook to handle upload progress. http://us.php.net/features.file-upload#71564
More explanation:
http://www.dinke.net/blog/2006/11/04/php-52-upload-progress-meter/en/
http://blog.liip.ch/archive/2006/09/10/upload-progress-meter-extension-for-php-5-2.html
Rasmus' Example:
http://progphp.com/progress.phps
You can try YUI or Prototype or JQuery
From PHP 5.4 it is in session extension: http://php.net//manual/pl/session.upload-progress.php
In pure PHP, you are correct: it's not possible.
If you AJAX-ify this, then you could do what you're describing. The only progress meters I've ever seen are in Javascript or Flash, though I imagine Silverlight could do it also.
"Old school", but a PHP + Perl technique: http://www.raditha.com/php/progress.php
In my opinion, the best / easiest solution is to build a small flash widget, that consists of an 'Upload' button and a progress bar. Flash gives you very detailed feedback on how much data has been uploaded so far, and you can build a nice progress bar based on that. Doesn't require inefficient polling of the server, and in fact doesn't require any changes at all to your server code. Google for 'flash uploader' and you'll find many people have already written these widgets and are happy to sell them to you for a buck.
I'd recommend looking at SWFUpload to accomplish what you want. It's fairly flexible and supports queueing of files, so you could even handle multi-file uploads.
You will definately want to go with digitgerald's FancyUpload. It's Mootools & swfuplaod based, and it sports a nice queue with statusses, progress, eta etc. It's really the slickest method i've seen for uploading files. For my personal use case ivé used it to let the client select 1.2 gb of PDF files and upload them. Newer ones get renamed and versioned automatically, same are skipped, etc.

Categories