Example #1
0
function submit_photo()
{
    $dir = "../images";
    $pid = intval(get_http_var('pid'));
    $errors = array();
    if (!array_key_exists('photo', $_FILES)) {
        array_push($errors, 'Not got the photo.');
    } elseif ($_FILES['photo']['error'] > 0) {
        array_push($errors, 'There was an error uploading the photo.');
    } elseif (!is_uploaded_file($_FILES['photo']['tmp_name'])) {
        array_push($errors, 'Did not get an uploaded file.');
    } else {
        $tmp_name = $_FILES['photo']['tmp_name'];
        $image = imagick_readimage($tmp_name);
        if (!$image) {
            array_push($errors, 'Failed to read image from uploaded file');
        }
        $imageS = imagick_clonehandle($image);
        if (!imagick_scale($image, 118, 118, false)) {
            array_push($errors, 'Scaling large failed');
        }
        if (!imagick_scale($imageS, 59, 59, false)) {
            array_push($errors, 'Scaling small failed');
        }
        if (!imagick_writeimage($image, "{$dir}/mpsL/{$pid}.jpeg")) {
            array_push($errors, "Saving to {$dir}/mpsL/{$pid}.jpeg failed");
        }
        if (!imagick_writeimage($imageS, "{$dir}/mps/{$pid}.jpeg")) {
            array_push($errors, "Saving to {$dir}/mps/{$pid}.jpeg failed");
        }
        if (!$errors) {
            print "<pre>";
            chdir("{$dir}/mpsL");
            passthru("cvs -Q add -kb {$pid}.jpeg 2>&1");
            chdir("../mps");
            passthru("cvs -Q add -kb {$pid}.jpeg 2>&1");
            chdir("../");
            passthru('cvs -Q commit -m "Photo update from admin web photo upload interface." mpsL mps 2>&1');
            print "</pre>";
        }
    }
    if ($errors) {
        return display_form($errors);
    }
    return "<p><em>Photo uploaded and resized for pid {$pid}</em> &mdash; check how it looks <a href=\"/mp?p={$pid}\">on their page</a></p>" . display_form();
}
function image_imagick()
{
    $tous = func_get_args();
    $img = $tous[0];
    $fonc = $tous[1];
    $tous[0] = "";
    $tous_var = join($tous, "-");
    $fonction = array('image_imagick', func_get_args());
    $image = _image_valeurs_trans($img, "{$tous_var}", "png", $fonction);
    if (!$image) {
        return "";
    }
    $im = $image["fichier"];
    $dest = $image["fichier_dest"];
    $creer = $image["creer"];
    if ($creer) {
        if (function_exists($fonc)) {
            $handle = imagick_readimage($im);
            $arr[0] = $handle;
            for ($i = 2; $i < count($tous); $i++) {
                $arr[] = $tous[$i];
            }
            call_user_func_array($fonc, $arr);
            // Creer image dans fichier temporaire, puis renommer vers "bon" fichier
            // de facon a eviter time_out pendant creation de l'image definitive
            $tmp = preg_replace(",[.]png\$,i", "-tmp.png", $dest);
            imagick_writeimage($handle, $tmp);
            rename($tmp, $dest);
            ecrire_fichier($dest . ".src", serialize($image));
        }
    }
    list($src_y, $src_x) = taille_image($dest);
    return _image_ecrire_tag($image, array('src' => $dest, 'width' => $src_x, 'height' => $src_y));
}
function bilder($width,$height,$dest) {
	//Wenn auf dem Server die php_imagick nicht installiert werden kann:
        //$rc=@exec("/usr/bin/convert -resize ".$width."x".$height." tmp/tmp.file_org tmp/tmp.file_$dest",$aus,$rc2);
        //if ($rc2>0) { echo "[Bildwandeln: $image.$dest]<br>";  return false; };

	if (!function_exists("imagick_readimage")) { echo "Imagick-Extention nicht installiert"; return false; };
	$handle=imagick_readimage("./tmp/tmp.file_org");
	if (!$handle) {
		$reason      = imagick_failedreason( $handle ) ;
		print "Lesen: $reason<BR>\n" ; flush();
		return false;
	}
	if (!imagick_resize( $handle, $width, $height, IMAGICK_FILTER_UNKNOWN, 0)) {
		$reason      = imagick_failedreason( $handle ) ;
		print "Resize: $reason<BR>\n" ;	flush();
		return false;
	}
	if (!imagick_writeimage( $handle,"./tmp/tmp.file_$dest")) {
		$reason      = imagick_failedreason( $handle ) ;
		print "Schreiben: $reason<BR>\n" ; 	flush();
		return false;
	}
	return true;
}
Example #4
0
function bilder($width, $height, $dest)
{
    if (!function_exists("imagick_readimage")) {
        echo "Imagick-Extention nicht installiert";
        return false;
    }
    $handle = imagick_readimage("./tmp/tmp.file_org");
    if (!$handle) {
        $reason = imagick_failedreason($handle);
        print "Lesen: {$reason}<BR>\n";
        flush();
        return false;
    }
    if (!imagick_resize($handle, $width, $height, IMAGICK_FILTER_UNKNOWN, 0)) {
        $reason = imagick_failedreason($handle);
        print "Resize: {$reason}<BR>\n";
        flush();
        return false;
    }
    if (!imagick_writeimage($handle, "./tmp/tmp.file_{$dest}")) {
        $reason = imagick_failedreason($handle);
        print "Schreiben: {$reason}<BR>\n";
        flush();
        return false;
    }
    return true;
}
Example #5
0
 function resize_file_IMagick(&$file, $create)
 {
     $handle = imagivk_readimage(getcwd() . '/' . $this->upload->path . '/' . $this->orgFileName);
     if (imagick_iserror($handle)) {
         $reason = imagick_failedreason($handle);
         $description = imagick_faileddescription($handle);
         echo "Handle failed!<br/>Reason: {$reason}<br/>Description: {$description}";
         exit;
     }
     if (!imagick_resize($handle, $this->newWidth, $this->newHeight, IMAGICK_FILTER_UNKNOWN, 0, "!")) {
         $reason = imagick_failedreason($handle);
         $description = imagick_faileddescription($handle);
         echo "imagick_resize() failed!<br/>Reason: {$reason}<br/>Description: {$description}";
         exit;
     }
     //Set the extension of the new file
     $ext = $this->GetNewfileExtension();
     if (file_exists($this->upload->path . '/' . $file->name . "." . $ext) && $file->name . "." . $ext != $file->fileName && $this->upload->nameConflict == "uniq") {
         $file->setFileName($this->upload->createUniqName($file->name . ".jpg"));
     }
     if ($create == "image") {
         $fileName = $file->name . "." . $ext;
         @unlink($this->upload->path . '/' . $this->orgFileName);
         if (!imagick_writeimage($handle, getcwd() . '/' . $this->upload->path . '/' . $fileName)) {
             $reason = imagick_failedreason($handle);
             $description = imagick_faileddescription($handle);
             echo "imagick_writeimage() failed!<br/>Reason: {$reason}<br/>Description: {$description}";
             exit;
         }
         $file->setFileName($fileName);
     } else {
         if ($this->pathThumb == "") {
             $this->pathThumb = $this->upload->path;
         }
         if ($this->naming == "suffix") {
             $fileName = $file->name . $this->suffix . "." . $ext;
         } else {
             $fileName = $this->suffix . $file->name . "." . $ext;
         }
         if (!imagick_writeimage($handle, getcwd() . '/' . $this->pathThumb . '/' . $fileName)) {
             $reason = imagick_failedreason($handle);
             $description = imagick_faileddescription($handle);
             echo "imagick_writeimage() failed!<br/>Reason: {$reason}<br/>Description: {$description}";
             exit;
         }
         $file->setThumbFileName($fileName, $this->pathThumb, $this->naming, $this->suffix);
     }
 }
Example #6
0
 function _createBitmap($src)
 {
     // depends on imagick!
     if (!extension_loaded('imagick')) {
         dl('imagick.so');
     }
     // we litter files a bit here.. - we should do a clean up really..
     $srcTmp = ini_get('session.save_path') . '/' . uniqid('xsw_') . '_' . basename($src);
     $data = file_get_contents($src);
     $fh = fopen($srcTmp, 'w');
     fwrite($fh, $data);
     fclose($fh);
     $handle = imagick_readimage($srcTmp);
     $ret = ini_get('session.save_path') . '/' . uniqid('xsw_') . '_' . basename($src) . '.bmp';
     imagick_writeimage($handle, $ret);
     unlink($srcTmp);
     return $ret;
 }
Example #7
0
 public function landscape()
 {
     if (!HAS_IMAGICK) {
         throw new Exception('Landscape graphs need IMagick installed');
     }
     $filename = $this->makeFileName(true);
     $source = imagick_readimage($filename);
     $rotate = imagick_rotate($source, 270);
     imagick_writeimage($source, $filename);
 }
Example #8
0
/**
 * Given a path under dataroot, an ID and a size, return the path to a file
 * matching all criteria.
 *
 * If the file with the ID exists but not of the correct size, this function
 * will make a copy that is resized to the correct size.
 *
 * @param string $path The base path in dataroot where the image is stored. For 
 *                     example, 'artefact/file/profileicons/' for profile 
 *                     icons
 * @param int $id      The ID of the image to return. Is typically the ID of an 
 *                     artefact
 * @param mixed $size  The size the image should be.
 *
 *                      As a two element hash with 'w' and 'h' keys:
 *                     - If 'w' and 'h' are not empty, the image will be 
 *                       exactly that size
 *                     - If just 'w' is not empty, the image will be that wide, 
 *                       and the height will be set to make the image scale 
 *                       correctly
 *                     - If just 'h' is not empty, the image will be that high, 
 *                       and the width will be set to make the image scale 
 *                       correctly
 *                     - If neither are set or the parameter is not set, the 
 *                       image will not be resized
 *
 *                     As a number, the path returned will have the largest side being 
 *                     the length specified.
 * @return string The path on disk where the appropriate file resides, or false 
 *                if an appropriate file could not be located or generated
 */
function get_dataroot_image_path($path, $id, $size = null)
{
    $dataroot = get_config('dataroot');
    $imagepath = $dataroot . $path;
    if (substr($imagepath, -1) == '/') {
        $imagepath = substr($imagepath, 0, -1);
    }
    if (!is_dir($imagepath) || !is_readable($imagepath)) {
        return false;
    }
    // Work out the location of the original image
    $originalimage = $imagepath . '/originals/' . $id % 256 . "/{$id}";
    // If the original has been deleted, then don't show any image, even a cached one.
    // delete_image only deletes the original, not any cached ones, so we have
    // to make sure the original is still around
    if (!is_readable($originalimage)) {
        return false;
    }
    if (!$size) {
        // No size has been asked for. Return the original
        return $originalimage;
    } else {
        // Check if the image is available in the size requested
        $sizestr = serialize($size);
        $md5 = md5("{$id}.{$sizestr}");
        $resizedimagedir = $imagepath . '/resized/';
        check_dir_exists($resizedimagedir);
        for ($i = 0; $i <= 2; $i++) {
            $resizedimagedir .= substr($md5, $i, 1) . '/';
            check_dir_exists($resizedimagedir);
        }
        $resizedimagefile = "{$resizedimagedir}{$md5}.{$id}";
        //.$sizestr";
        if (is_readable($resizedimagefile)) {
            return $resizedimagefile;
        }
        // Image is not available in this size. If there is a base image for
        // it, we can make one however.
        if (is_readable($originalimage)) {
            $imageinfo = getimagesize($originalimage);
            $originalmimetype = $imageinfo['mime'];
            switch ($originalmimetype) {
                case 'image/jpeg':
                case 'image/jpg':
                    $oldih = imagecreatefromjpeg($originalimage);
                    break;
                case 'image/png':
                    $oldih = imagecreatefrompng($originalimage);
                    break;
                case 'image/gif':
                    $oldih = imagecreatefromgif($originalimage);
                    break;
                case 'image/bmp':
                case 'image/x-bmp':
                case 'image/ms-bmp':
                case 'image/x-ms-bmp':
                    if (!extension_loaded('imagick')) {
                        log_info('Bitmap image detected for resizing, but imagick extension is not available');
                        return false;
                    }
                    $ih = imagick_readimage($originalimage);
                    if (!($newdimensions = image_get_new_dimensions(imagick_getwidth($ih), imagick_getheight($ih), $size))) {
                        return false;
                    }
                    imagick_resize($ih, $newdimensions['w'], $newdimensions['h'], IMAGICK_FILTER_LANCZOS, 1);
                    if (imagick_writeimage($ih, $resizedimagefile)) {
                        return $resizedimagefile;
                    }
                    return false;
                default:
                    return false;
            }
            if (!$oldih) {
                return false;
            }
            $oldx = imagesx($oldih);
            $oldy = imagesy($oldih);
            if (!($newdimensions = image_get_new_dimensions($oldx, $oldy, $size))) {
                return false;
            }
            $newih = imagecreatetruecolor($newdimensions['w'], $newdimensions['h']);
            if ($originalmimetype == 'image/png' || $originalmimetype == 'image/gif') {
                // Create a new destination image which is completely
                // transparent and turn off alpha blending for it, so that when
                // the PNG source file is copied, the alpha channel is retained.
                // Thanks to http://alexle.net/archives/131
                $background = imagecolorallocate($newih, 0, 0, 0);
                imagecolortransparent($newih, $background);
                imagealphablending($newih, false);
                imagecopyresampled($newih, $oldih, 0, 0, 0, 0, $newdimensions['w'], $newdimensions['h'], $oldx, $oldy);
                imagesavealpha($newih, true);
            } else {
                // imagecopyresized is faster, but results in noticeably worse image quality.
                // Given the images are resized only once each time they're
                // made, I suggest you just leave the good quality one in place
                imagecopyresampled($newih, $oldih, 0, 0, 0, 0, $newdimensions['w'], $newdimensions['h'], $oldx, $oldy);
                //imagecopyresized($newih, $oldih, 0, 0, 0, 0, $newdimensions['w'], $newdimensions['h'], $oldx, $oldy);
            }
            $result = imagepng($newih, $resizedimagefile);
            if ($result) {
                return $resizedimagefile;
            }
        }
        // end attempting to build a resized image
    }
    // Image not available in any size
    return false;
}
 public function save($path)
 {
     $rc = imagick_writeimage($this->img, $path);
     return $rc;
 }
Example #10
0
function liberty_imagick0_rotate_image(&$pFileHash)
{
    $ret = FALSE;
    if (!empty($pFileHash['source_file']) && is_file($pFileHash['source_file'])) {
        $iImg = imagick_readimage($pFileHash['source_file']);
        if (!$iImg) {
            $pFileHash['error'] = $pFileHash['name'] . ' ' . tra("is not a known image file");
        } elseif (imagick_iserror($iImg)) {
            $pFileHash['error'] = imagick_failedreason($iImg) . imagick_faileddescription($iImg);
        } elseif (empty($pFileHash['degrees']) || !is_numeric($pFileHash['degrees'])) {
            $pFileHash['error'] = tra('Invalid rotation amount');
        } else {
            if (!imagick_rotate($iImg, $pFileHash['degrees'])) {
                $pFileHash['error'] .= imagick_failedreason($iImg) . imagick_faileddescription($iImg);
            }
            if (!imagick_writeimage($iImg, $pFileHash['source_file'])) {
                $pFileHash['error'] .= imagick_failedreason($iImg) . imagick_faileddescription($iImg);
            }
        }
    } else {
        $pFileHash['error'] = "No source file to resize";
    }
    return empty($pFileHash['error']);
}