image_type = $image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { $this->image = imagecreatefromjpeg($filename); } elseif( $this->image_type == IMAGETYPE_GIF ) { $this->image = imagecreatefromgif($filename); } elseif( $this->image_type == IMAGETYPE_PNG ) { $this->image = imagecreatefrompng($filename); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image,$filename,$compression); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image,$filename); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image,$filename); } if( $permissions != null) { chmod($filename,$permissions); } } function output($image_type=IMAGETYPE_JPEG) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image); } } function getWidth() { return imagesx($this->image); } function getHeight() { return imagesy($this->image); } function resizeToHeight($height) { $ratio = $height / $this->getHeight(); $width = $this->getWidth() * $ratio; $this->resize($width,$height); } function resizeToWidth($width) { $ratio = $width / $this->getWidth(); $height = $this->getheight() * $ratio; $this->resize($width,$height); } function scale($scale) { $width = $this->getWidth() * $scale/100; $height = $this->getheight() * $scale/100; $this->resize($width,$height); } function resize($thumb_width,$thumb_height) { $width = imagesx($this->image); $height = imagesy($this->image); $original_aspect = $width / $height; $thumb_aspect = $thumb_width / $thumb_height; if($original_aspect >= $thumb_aspect) { $new_height = $thumb_height; $new_width = $width / ($height / $thumb_height); } else { $new_width = $thumb_width; $new_height = $height / ($width / $thumb_width); } $thumb = imagecreatetruecolor($thumb_width, $thumb_height); // Resize and crop imagecopyresampled($thumb, $this->image, 0 - ($new_width - $thumb_width) / 2, // Center the image horizontally 0 - ($new_height - $thumb_height) / 2, // Center the image vertically 0, 0, $new_width, $new_height, $width, $height); $this->image = $thumb; } } require_once( dirname(__FILE__) . '/../../wp-config.php' ); $args = array( 'posts_per_page' => 1, 'orderby' => 'date', 'order' => 'DESC' ); $posts = get_posts( $args ); header('Content-Type: image/jpeg'); if (!file_exists("cache/".$posts[0]->ID.".jpg")) { $image = wp_get_attachment_image_src( get_post_thumbnail_id( $posts[0]->ID ) ); $image_local_path = preg_replace('/\?.*/', '', substr($image[0], stripos($image[0], "/media/"))); $simpleImage = new SimpleImage(); $simpleImage->load("../..$image_local_path"); $simpleImage->resize(100,40); $simpleImage->save("cache/".$posts[0]->ID.".jpg"); } header("X-SendFile: cache/".$posts[0]->ID.".jpg"); ?>