Skip to content

Instantly share code, notes, and snippets.

@killercup
Created December 25, 2008 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killercup/39943 to your computer and use it in GitHub Desktop.
Save killercup/39943 to your computer and use it in GitHub Desktop.
<?php // $thumburl ist die URL des Bildes bei Flickr (1024er Version normalerweise)
$thumburl = get_post_meta($post->ID, 'thumbnail', true);
// Aus $thumbname und $upload_path setzt sich der absolute Pfad der Datei zusammen
$thumbname = "thumbnails/".$post->ID."-800.jpg";
$upload_path = ABSPATH.get_option("upload_path");
// Sofern es die Datei noch nicht gibt, erstellen wir sie mal eben
if(!file_exists($upload_path."/".$thumbname)) {
// Datei von Flickr temporär laden
file_put_contents("cache-" . $post->ID . ".jpg", file_get_contents($thumburl));
// Imagick soll die temp. Datei öffnen...
$thumb = new Imagick("cache-" . $post->ID . ".jpg");
// ... schön verkleinern...
$thumb->resizeImage(800,800,Imagick::FILTER_LANCZOS,1,true);
$thumb->setCompression(Imagick::COMPRESSION_JPEG);
$thumb->setCompressionQuality(80);
// ... und als platzsparendes JPG unter dem Dateinamen von oben speichern.
$thumb->writeImage($upload_path."/".$thumbname);
// Jetzt noch aufräumen.
$thumb->destroy();
unlink("cache-" . $post->ID . ".jpg");
}
// Die URL zu unserem Bild.
$thumbnail = get_option("fileupload_url").'/'.$thumbname;
// Die Farbe des Rahmens, nicht zu vernachlässigen!
$frame = get_post_meta($post->ID, 'frame', true);
// Sowie die URL des Bildes (auf Flickr, Zooomr, o.ä.)
$url = get_post_meta($post->ID, 'url', true);
// Und fertig! ?>
<img src="<?php echo $thumbnail; ?>" alt="<?php the_title(); ?>" style="background: <?php echo $frame; ?>" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment