Created
December 25, 2008 19:59
-
-
Save killercup/39943 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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