", "#", "\"", "/", "\\", "*", "?", "|"); return str_replace($to_remove, '', $file); } function makeThumb($item = "") { if ( $item == "" ) { return false; } $prefix = (substr(getcwd(), -4) == "ajax") ? "../" : ""; if ( is_dir($item) ) { $isfolder = true; $folder = $item; $files = array(); if ( $fh = opendir($folder) ) { while ( false !== ($entry = readdir($fh)) ) { if ( is_file($item . "/" . $entry) ) { $files[] = $entry; } } closedir($fh); natsort($files); } if ( count($files) == 0 ) { return false; } reset($files); $comic = $folder . "/" . current($files); $outfile = $prefix . THUMBSDIR . substr($folder, strlen(COMICSDIR)) . "_oem"; } elseif ( is_file($item) ) { $isfolder = false; $file = $item; $comic = $file; $targetdir = $prefix . THUMBSDIR . substr(dirname($file), strlen(COMICSDIR)) . "/"; if ( !is_dir($targetdir) ) { mkdir($targetdir, 0755, true); } $outfile = $targetdir . substr(basename($file), 0, -4) . "_oem"; } else { return false; } if ( substr($comic, -3) == "cbz" ) { $zip = new ZipArchive(); $opened = $zip->open($comic); if ( !$opened ) { return false; } $lowest = "~"; $imgdata = null; for ( $i=0; $i<$zip->numFiles; $i++ ) { $imgname = basename($zip->getNameIndex($i)); $parts = pathinfo($imgname); if ( isset($parts['extension']) ) { $imgext = strtolower($parts['extension']); if ( (strcmp($lowest, $imgname) > 0) && in_array($imgext, VALIDIMAGETYPES) ) { $lowest = $imgname; $imgdata = $zip->getFromIndex($i); } } } $zip->close(); if ( is_null($imgdata) ) return false; $didwrite = file_put_contents($outfile, $imgdata); if ( !$didwrite ) return false; } elseif ( substr($comic, -3) == "cbr" ) { $rar_file = rar_open($comic); if ( $rar_file === false ) { return false; } $entries = rar_list($rar_file); $lowest = "~"; foreach ( $entries as $entry ) { $imgname = $entry->getName(); $parts = pathinfo($imgname); if ( isset($parts['extension']) ) { $imgext = strtolower($parts['extension']); if ( (strcmp($lowest, $imgname) > 0) && in_array($imgext, VALIDIMAGETYPES) ) { $lowest = $imgname; $didwrite = $entry->extract(false, $outfile); if ( !$didwrite ) { return false; } } } } rar_close($rar_file); } else { return false; } $input = new Imagick($outfile); $input->setImageFormat("jpg"); $width = $input->getImageWidth(); $height = $input->getImageHeight(); $scale = 300 / $width; $newx = 300; $newy = intval($height * $scale); if ( $newy > 450 ) { $newy = 450; $scale = $height / 450; $newx = intval($width / $scale); } $thumb = substr($outfile, 0, -4) . ".jpg"; $thumb = str_replace("#", "", $thumb); $input->resizeImage($newx, $newy, Imagick::FILTER_SINC, 1); $written = file_put_contents($thumb, $input->getImageBlob()); unlink($outfile); return (($written === false) ? false : true); } // vim: set ai et ts=3 sw=3: