Automatic thumbnails

software development

#1

Hi everyone, I really hope there is a way to do this with php on dh: if I have a ./images directory with a ./images/tn subdirectory; whenever a user uploads a photo to ./images, a copy is sent to the tn subdir and with imagemagick make a thumbnail thusly: mogrify -geometry 200 someimage.jpg ? I know that exec() is disabled but has anyone figured out way to do this? I know that there are gallery programs, but I really only want this function. Thanks!!


#2

I did exactly that this weekend actually.

What you’ll need to do is have the script run as PHP-CGI. To do this, just change the file extension to .pcgi. You can also modify your .htaccess to make .php (or any other extension) files run as PHP-CGI too: https://kbase.newdream.net/index.cgi?area=2526


#3

I have a file “exec.pcgi” which contains:

<? $command="mogrify -geometry 200 ./images/users/nicole0.jpg"; exec("$command"); ?>

This doesn’t work for some reason. Exec.pcgi sits in the same folder as “images”. Could you please show some of your code in case I’m overlooking something? Thanks again!


#4

Here is what I used to make my thumbnails.

$current_file is the image I’m resizing.
$thumb_file is the thumbnail I want to make.

exec("/usr/bin/X11/convert -geometry $new_img_width\x$new_img_height $current_file $thumb_file", $retval);


#5

A big thank you for that retrograde, works perfect here.

may I ask… what the /usr/bin/x11 path means exactly, and how did you detemine it ?


#6

‘/usr/bin/X11/’ is the directory the program ‘convert’ is in on the server.

You can get the path to it by logging into the shell via SSH or Telnet, and typing ‘which .’

[zebes]$ which convert
/usr/bin/X11/convert

This is useful if you’re writing scripts that might need to reference directories or files on the server.


#7

thanx again for that. I have some experience with php and mysql and make sites for years, but here is my first “telnet possible” hosting, I never touched a unix box before, so I have a lot to learn, basics like this “which” command…

If someone knows of website/tutorial in line for my (not so rare) case… Something like “unix through telnet or ssh for webmasters”…


#8

I just did a search for “unix for webmasters” and came across the following… http://www.verysimple.com/scripts/support_unix.html.

It’s very basic, but it will probably get you started.

And if you can… always login via SSH. Telnet doesn’t encrypt the data you send and receive. There are a couple free SSH clients out there, like PuTTY: http://www.chiark.greenend.org.uk/~sgtatham/putty/.


#9

verysimple but nice, helpful for me, thanx again !

I already use SSH with putty, as advised in DH knowledge base. It’s really great to discover something, improving quickly at the beginning :wink:
I installed and tested a search engine perl script (perlfect.com), and found it very powerful (but it seems some Perl modules are missing here, for parsing through http).

Mmm… just in case you are still there… I just wonder if there is a magic key/command to repeat the last command(s) ??


#10

Press the ‘up’ arrow key on your keyboard. This navigates through a list of the last 30~ or so commands you have used. No matter where you login from, they will still be there for you to use as they are kept on the server in a file in your home directory.

Hope this helps.

  • wil

#11

Hey, this was hugely coincidental that I stumbled on this thread! (Led here by the newletter, forgot all about this forum, heh.) I just finished a simple no-brainer script for this thing, which only works on Dreamhost as far as I know. (It needs php-cgi, and Imagemagick, can’t guarantee that everywhere!) I was aksing myself…

Q: What should I do, sell it for millions of dollars, or give it away?
A: Give it away. Nobody will give me millions of dollars anyway. :wink:

DEMO: http://seavisions.dreamhost.com/archives/index.php
ZIP: http://www.znippets.com/ZIP/autoThumbs.zip

Now I built this thing to work on any Dreamhost server, just drop the contents of the ZIP into the directory that contains your images and directories of images, it should just work, auto-generating thumbnails, and launching a new browser window if you click on the thumbs. (Since it’s geared for Dreamhost, it uses ImageMagick instead of NetPBM or the GD libraries. What a cool program! How poorly documented! Woo.) You can adjust a few parameters, set the number of images to display at a time, or another variable for a different path to ImageMagick. Set these two variables…

$displayMany = 12; // <==!!! key value, only display ‘X’ at a time.
$pathToMogrify = “/usr/X11R6/bin/mogrify”;

…or simply leave it alone, it should work right out of the box, no modifications needed. Tested only on Dreamhost, I assume that the $pathToMogrify would be different on different hosts, and I’ve included an .htaccess to set .php files to run as php-cgi instead. (Runs with permissions as “you”.) I also put in a catch to stop folks from browsing …/…/…/.passwd files, etc… If any of you hard core server programmers note some other obvious security issues, please, tell me about them!

Have fun, I’d love to hear how this works for others here.

Your pal, -doc-

(edit: what, no auto linking of urls? :wink:

“Specialization is for Insects”