[Clipart] Making our thumbnails comply with the thumbnail spec, i.e., 128x128px

Paul Reinheimer paul.clipart at sharethebeat.com
Fri Apr 29 16:56:57 PDT 2005


Hi,

When faced with a similar problem for a site of mine, I guess I went
with something like a hybrid approach. I was creating square-ish thumbnails
based on user images. I picked the largest side, scaled it down to fit,
applied the same scale to the other axis, and ensured it was still at
least 1px (to deal with edge cases where an image would be really tall but
very very thin). My qualifications were that the images be no larger than
75x75 (smaller was acceptible), but had i wanted all images to be 75x75 i 
would have just centered the resulting image on an otherwise transparent .png.

Images were never scaled up, smaller images were left as is. 

My code, for the curious was(/is?):


function makeThumbnail($sourceFile, $destFile)
{
  $S_im = imagecreatefromstring(file_get_contents($sourceFile));
  $S_info = getimagesize($sourceFile);
  $x = 0;
  $y = 0;
  $z = 0;
  if ($S_info[0] > 75 || $S_info[1] > 75)
  {
    if ($S_info[0] > $S_info[1])
    {
      $z = ($S_info[0] / 75);
      $x = intval($S_info[0] / $z);
      $y = intval($S_info[1] / $z);
    }else
    {
      $z = ($S_info[1] / 75);
      $x = intval($S_info[0] / $z);
      $y = intval($S_info[1] / $z);
    }
    if ($x == 0)
    {
      $x = 1;
    }
    if ($y == 0)
    {
      $y = 1;
    }
  }else
  {
    $x = $S_info[0];
    $y = $S_info[1];
  }
  $D_im = imagecreatetruecolor($x, $y);
  imagecopyresampled ($D_im, $S_im, 0, 0, 0, 0, $x, $y, $S_info[0], $S_info[1]);
  imagepng($D_im,$destFile);
  return array($x, $y);
}


paul



> ------------Original Message------------
> From: "Jonadab the Unsightly One" <jonadab at bright.net>
> To: "Open Clip Art Library" <clipart at lists.freedesktop.org>
> Date: Fri, Apr-29-2005 7:24 PM
> Subject: [Clipart]  Making our thumbnails comply with the thumbnail spec, i.e., 128x128px
>
> 
> At some point (not for this release), we will want to make the
> thumbnails in our packages usable by apps that use the fdo thumbnail
> specification for thumbnails.  The (theoretical, currently
> non-existent -- thus, no hurry) unpackager/installer will handle
> storing them in the right location on the filesystem according to the
> spec, but it can avoid having to parse any SVG or generate any
> thumbnails itself if the thumbnails we provide are usable.  We already
> use PNG, which is the format the spec sanctions, so we're partway
> there, but...  they will have to be square, 128x128 pixels (for
> "normal" size, which is the smallest size specified in the spec).  Of
> course, many of the images aren't anywhere near square in shape, and
> stretching them in a way that distorts the aspect ratio seems to me
> like the wrong approach.
> 
> So, here's a thread where we can discuss what the right approach is.
> Cropping to a square or centering (on a square background) are the
> other obvious approaches.  Is one of these less evil than the other?
> Would a combination of the two be a good compromise, or the worst of
> both worlds?  Discuss.
> 
> -- 
> $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}}
> split//,"ten.thgirb\@badanoj$/ --";$\=$ ;-> ();print$/
> 
> _______________________________________________
> clipart mailing list
> clipart at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/clipart
> 




More information about the clipart mailing list