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> — check how it looks <a href=\"/mp?p={$pid}\">on their page</a></p>" . display_form(); }
/** * @param $newx * @param $newy * @return bool */ function resizeImage($newx, $newy) { if (!isset($this->imagehandle)) { $this->readimagefromstring(); } if (!isset($this->xsize)) { $this->getimageinfo(); } if ($this->xsize * $this->ysize == 0) { $this->repairimageinfo(); } if ($this->uselib == "imagick") { if (!imagick_scale($this->imagehandle, $newx, $newy, "!")) { $reason = imagick_failedreason($handle); $description = imagick_faileddescription($handle); // todo: Build in error handler in imagegallib exit; } } else { if ($this->uselib == "gd") { if ($this->gdversion >= 2.0) { $t = imagecreatetruecolor($newx, $newy); imagecopyresampled($t, $this->imagehandle, 0, 0, 0, 0, $newx, $newy, $this->xsize, $this->ysize); } else { $t = imagecreate($newx, $newy); $this->ImageCopyResampleBicubic($t, $this->imagehandle, 0, 0, 0, 0, $newx, $newy, $this->xsize, $this->ysize); } $this->imagehandle = $t; } } // fill $this->image for writing or output $this->writeimagetostring(); // reget sizes $this->getimageinfo(); //set new sizes $this->xsize = $newx; $this->ysize = $newy; return true; }
/** * @param $x * @param $y * @return mixed */ function _resize($x, $y) { if ($this->data) { return imagick_scale($this->data, $x, $y); } }
public function scale($width, $height) { $rc = imagick_scale($this->img, $width, $height); return $rc; }