Esempio n. 1
0
function pdftojpg($pdfFile, $jpgFile)
{
    /*  
     * imagemagick and php5-imagick required 
     * 
     * all options for imagick: 
     *           http://php.net/manual/fr/class.imagick.php 
     * 
     */
    $pdf_file = $pdfFile;
    $save_to = $jpgFile;
    $img = new imagick();
    //this must be called before reading the image, otherwise has no effect - "-density {$x_resolution}x{$y_resolution}"
    //this is important to give good quality output, otherwise text might be unclear
    $img->setResolution(200, 200);
    //read the pdf
    $img->readImage("{$pdf_file}[0]");
    //reduce the dimensions - scaling will lead to black color in transparent regions
    $img->scaleImage(1920, 1080);
    //set new format
    $img->setCompressionQuality(80);
    $img->setImageFormat('jpg');
    // -flatten option, this is necessary for images with transparency, it will produce white background for transparent regions
    $img = $img->flattenImages();
    //save image file
    $img->writeImages($save_to, false);
    //clean
    $img->clear();
    $img->destroy();
}
Esempio n. 2
0
function makethumb($srcFile, $dstFile, $dstW, $dstH, $imwf = false)
{
    $im = new imagick($srcFile);
    $source_w = $im->getImageWidth();
    $source_h = $im->getImageHeight();
    if ($dstW === 0 && $dstH === 0) {
        $dstW = $source_w;
        $dstH = $source_h;
    } else {
        // 取得縮在此範圍內的比例
        $percent = getResizePercent($source_w, $source_h, $dstW, $dstH);
        $dstW = $source_w * $percent;
        $dstH = $source_h * $percent;
    }
    $im->thumbnailImage($dstW, $dstH);
    $im->writeImage($dstFile);
    $watermarkFile = './logo.png';
    if ($imwf && is_file($watermarkFile) && is_file($dstFile)) {
        $image = new imagick($dstFile);
        $watermark = new imagick($watermarkFile);
        $iWidth = $image->getImageWidth();
        $iHeight = $image->getImageHeight();
        $wWidth = $watermark->getImageWidth();
        $wHeight = $watermark->getImageHeight();
        if ($iHeight < $wHeight || $iWidth < $wWidth) {
            $watermark->scaleImage($iWidth, $iHeight);
            $wWidth = $watermark->getImageWidth();
            $wHeight = $watermark->getImageHeight();
        }
        $x = ($iWidth - $wWidth) / 2;
        $y = ($iHeight - $wHeight) / 2;
        $image->compositeImage($watermark, imagick::COMPOSITE_OVER, $x, $y);
        $image->writeImage($dstFile);
    }
}
Esempio n. 3
0
 function thumbnail($file, $width = '120')
 {
     $name = $this->_dir . DS . $file . '[0]';
     $im = new imagick($name);
     $im->setImageFormat('jpg');
     $im->scaleImage($width, 0);
     header('Content-Type: image/jpeg');
     echo $im;
 }
Esempio n. 4
0
 private function createThumb($filePath, $fileName)
 {
     if (!extension_loaded('imagick')) {
         $errorMessage = "Error: 874";
         $this->error($errorMessage);
     }
     try {
         $fileNameWithoutExt = $fileName;
         $imagePreview = new imagick($this->uploadsDir . $fileName);
         $imagePreview->scaleImage(300, 0);
         $imagePreview->writeImage($this->thumbDir . $fileNameWithoutExt);
     } catch (ImagickException $e) {
         $errorMessage = "Error: 3435";
         $this->error($errorMessage);
     }
     return $fileNameWithoutExt;
 }
 function get_texture($uuid, $x = null, $y = null)
 {
     $image = $this->ci->curl->simple_get($this->asset_service . $uuid);
     if ($image == null) {
         return null;
     }
     $im = new imagick();
     $im->readImageBlob($image);
     $im->setImageFormat("jpeg");
     if ($x != null && $y != null) {
         $im->scaleImage(200, 200, true);
     }
     return $im;
 }
Esempio n. 6
0
ignore_user_abort(true);
set_time_limit(0);
// pixel cache max size
IMagick::setResourceLimit(imagick::RESOURCETYPE_MEMORY, 256);
// maximum amount of memory map to allocate for the pixel cache
IMagick::setResourceLimit(imagick::RESOURCETYPE_MAP, 256);
$mid = $_REQUEST['mid'];
mkdir("../upload/");
$fname = md5($file_name[1] . date() . rand(0, 100000)) . ".jpg";
while (file_exists("../../magazine/" . $mid . "/" . $fname)) {
    $fname = md5($file_name[1] . date() . rand(0, 100000)) . ".jpg";
}
move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/" . $fname);
$img = new imagick();
$img->setResolution(500, 500);
$img->readimage("../upload/" . $fname);
$img->scaleImage(1000, 0);
$img->writeImage("../../magazine/" . $mid . "/" . $fname);
$img->scaleImage(200, 0);
$img->writeImage("../../magazine/" . $mid . "/small/" . $fname);
include "conn.php";
$sql = "SELECT `magazine`.`size` FROM `magazine` WHERE `magazine`.`id`=" . $mid . "";
$result = mysql_query($sql, $conn);
$row = mysql_fetch_array($result);
$sql = "INSERT INTO `pages` (`magazine`, `name`, `position`) VALUES (" . $mid . ", '" . $fname . "', '" . $row[0] . "');";
mysql_query($sql, $conn);
$sql = "UPDATE `magazine` SET size=size+1 WHERE `magazine`.`id`='" . $mid . "'";
mysql_query($sql, $conn);
echo mysql_insert_id($conn);
mysql_close($conn);
Esempio n. 7
0
function makethumbnail($page, $pdf_file, $thumb_path)
{
    $pdf_file = $pdf_file;
    $thumb_page = $page + 1;
    $img_save_to = $thumb_path . '/thumbnail_' . $thumb_page . '.jpg';
    $img = new imagick($pdf_file . "[" . $page . "]");
    $img->scaleImage(76, 100);
    $img->setImageFormat('jpg');
    $img = $img->flattenImages();
    $img->writeImage($img_save_to);
    chmod($img_save_to, 0777);
}