[Wylug-help] Image manipulation service/server

Gary Stainburn gary.stainburn at ringways.co.uk
Wed Jul 16 11:04:02 BST 2003


On Tuesday 15 Jul 2003 9:27 am, Felix Ulrich-Oltean wrote:
> Hi
>
> We have a number of systems (in Python, Perl and PHP) which all need
> to process images uploaded by users.  We want to produce images
> e.g. thumbnails of a consistent quality across these systems.  We are
> therefore considering making an "images sever" that wraps image
> manipulation stuff and is available to all our systems via some
> universal standard, e.g. http or xml-rpc or whatever else.
>
> Has anyone done such a thing already?
>
> Is there a better way of achieving our aim?
>
> Any suggestions as to what would make the most sensible way of
> implementing the image service and communicating between these
> systems?
>
> Thanks for any suggestions,
>
> Felix.

Hi Felix,

we've got a wrapper for one of our systems which generates missing thumbnails
for all images in a directory.  It should be a doddle to amend this to embed
it in an upload CGI so that it then generates the thumbnail and returns a URL
to it.

It uses Image Magick and the image Magick perl module.

Gary

#!/usr/bin/perl
use strict;

use Image::Magick;

my $im = Image::Magick->new;

umask 0022;

# if passed filenames use them, otherwise do all
my @names = @ARGV ? @ARGV : grep { -f and -B } <*>;

for (@names) {                        # foreach name
  if (/ /) {                          # if name contains a space
    my $old = $_;
    tr, ,_,s;                         # change spaces to _
    $_ .= ".jpg" unless /\.jpg$/;     # append .jpg if missing
    ! -e and rename $old, $_ or next; # skip file if rename fails
    warn "renaming $old to $_\n";
  }
  next if /\.thumb\.jpg$/;            # skip if this is thumbnail
  my $thumb = "$_.thumb.jpg";
  next if -e $thumb;                  # skip if thumbnail exists
  undef @$im;                         # reset (part of) $im
  my $ret;
  $ret = $im->Read($_)                # read file
    and warn($ret), next;             # or fail and skip
  $ret = $im->Scale(geometry => '100x100')
    and warn($ret), next;
  $ret = $im->Write($thumb)
    and warn($ret), next;
  warn "thumbnail made for $_\n";
}




>
> _______________________________________________
> Wylug-help mailing list
> Wylug-help at wylug.org.uk
> http://list.wylug.org.uk/mailman/listinfo/wylug-help

--
Gary Stainburn

This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000





More information about the Wylug-help mailing list