本文整理汇总了PHP中imagescale函数的典型用法代码示例。如果您正苦于以下问题:PHP imagescale函数的具体用法?PHP imagescale怎么用?PHP imagescale使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagescale函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resizeImage
public function resizeImage($imagePath, $new_width, $new_height)
{
$fileName = pathinfo($imagePath, PATHINFO_FILENAME);
$fullPath = pathinfo($imagePath, PATHINFO_DIRNAME) . "/" . $fileName . "_small.png";
if (file_exists($fullPath)) {
return $fullPath;
}
$image = $this->openImage($imagePath);
if ($image == false) {
return null;
}
$width = imagesx($image);
$height = imagesy($image);
$imageResized = imagecreatetruecolor($width, $height);
if ($imageResized == false) {
return null;
}
$image = imagecreatetruecolor($width, $height);
$imageResized = imagescale($image, $new_width, $new_heigh);
touch($fullPath);
$write = imagepng($imageResized, $fullPath);
if (!$write) {
imagedestroy($imageResized);
return null;
}
imagedestroy($imageResized);
return $fullPath;
}
示例2: actionPhoto
public function actionPhoto($id)
{
$model = $this->loadModel($id);
$model->scenario = 'photo';
Yii::trace("FC.actionPhoto called", 'application.controllers.FamilyController');
if (Yii::app()->params['photoManip']) {
if (isset($_POST['x1'])) {
$x1 = $_POST['x1'];
$y1 = $_POST['y1'];
$width = $_POST['width'];
$height = $_POST['height'];
$pfile = $_POST['pfile'];
$sdir = './images/uploaded/';
$size = getimagesize($sdir . $pfile);
if ($size) {
list($w, $h, $t) = $size;
} else {
Yii::trace("FR.actionPhoto crop call to getimagesize failed for image " . $sdir . $pfile . " returned {$size}", 'application.controllers.FamilyController');
}
Yii::trace("FC.actionPhoto crop received {$x1}, {$y1}, {$width}, {$height}, {$w}, {$h}, {$t}", 'application.controllers.FamilyController');
switch ($t) {
case 1:
$img = imagecreatefromgif($sdir . $pfile);
break;
case 2:
$img = imagecreatefromjpeg($sdir . $pfile);
break;
case 3:
$img = imagecreatefrompng($sdir . $pfile);
break;
case IMAGETYPE_BMP:
$img = ImageHelper::ImageCreateFromBMP($sdir . $pfile);
break;
case IMAGETYPE_WBMP:
$img = imagecreatefromwbmp($sdir . $pfile);
break;
default:
Yii::trace("FC.actionPhoto crop unknown image type {$t}", 'application.controllers.FamilyController');
}
if (function_exists('imagecrop')) {
# untested
$cropped = imagecrop($img, array('x1' => $x1, 'y1' => $y1, 'width' => $width, 'height' => $height));
$scaled = imagescale($cropped, 400);
} else {
$h = $height * 400 / $width;
$scaled = imagecreatetruecolor(400, $h);
imagecopyresized($scaled, $img, 0, 0, $x1, $y1, 400, $h, $width, $height);
}
$dir = './images/families/';
$fname = preg_replace('/\\.[a-z]+$/i', '', $pfile);
$fext = ".jpg";
if (file_exists($dir . $pfile)) {
$fname .= "_01";
while (file_exists($dir . $fname . $fext)) {
++$fname;
}
}
$dest = $dir . $fname . $fext;
imagejpeg($scaled, $dest, 90);
imagedestroy($scaled);
imagedestroy($img);
unlink($sdir . $pfile);
$model->photo = $fname . $fext;
$model->save(false);
Yii::trace("FC.actionPhoto saved to {$pfile}", 'application.controllers.FamilyController');
$this->redirect(array('view', 'id' => $model->id));
return;
} elseif (isset($_FILES['Families'])) {
Yii::trace("FC.actionPhoto _FILES[Families] set", 'application.controllers.FamilyController');
$files = $_FILES['Families'];
$filename = $files['name']['raw_photo'];
if (isset($filename) and '' != $filename) {
Yii::trace("FC.actionPhoto filename {$filename}", 'application.controllers.FamilyController');
$tmp_path = $files['tmp_name']['raw_photo'];
if (isset($tmp_path) and '' != $tmp_path) {
Yii::trace("FC.actionPhoto tmp_path {$tmp_path}", 'application.controllers.FamilyController');
$dir = "./images/uploaded/";
$dest = $dir . $filename;
list($width, $height) = getimagesize($tmp_path);
if ($width < 900) {
$w = $width;
$h = $height;
$zoom = 1;
} else {
$w = 900;
$h = $height * 900 / $width;
$zoom = $w / $width;
}
$w = $width < 900 ? $width : 900;
move_uploaded_file($tmp_path, $dest);
$this->render('crop', array('model' => $model, 'pfile' => $filename, 'width' => $w, 'height' => $h, 'zoom' => $zoom));
return;
} else {
$errors = array(1 => "Size exceeds max_upload", 2 => "FORM_SIZE", 3 => "No tmp dir", 4 => "can't write", 5 => "error extension", 6 => "error partial");
$error = $errors[$files['error']['raw_photo']];
Yii::trace("FC.actionPhoto file error {$error}", 'application.controllers.FamilyController');
}
}
}
} elseif (isset($_FILES['Families'])) {
//.........这里部分代码省略.........
示例3: resizeImage
/**
* Resize the image to the given co-ordinates
* + WIDTH 512
* + HEIGHT 512
* @param $image
* @return bool
*/
private function resizeImage($image)
{
if (($newImage = imagescale($image, 512, 512)) != false) {
$this->newImage = $newImage;
return true;
}
return false;
}
示例4: resize
/**
* resize file $source and save the resized image into $destination
*
* @param string $source file to resize
* @param string $destination resized file
* @throws ImageResizerException
*/
public function resize($source, $destination)
{
list($srcWidth, $srcHeight) = $this->retrieveSrcDimensions($source);
list($dstWidth, $dstHeight) = $this->calculateDstDimensions($srcWidth, $srcHeight);
$srcId = $this->getImageIdentifier($source);
$dstId = @imagescale($srcId, $dstWidth, $dstHeight, IMG_BILINEAR_FIXED);
@imageinterlace($dstId, $this->getOption(self::OPT_INTERLACE));
$this->save($dstId, $destination);
@imagedestroy($dstId);
}
示例5: handle
public function handle(FileUpload $uploader, FileInfo $fileinfo)
{
// TODO Auto-generated method stub
$filename = $fileinfo->getPath();
$realpath = $uploader->getFileBaseDir() . DIRECTORY_SEPARATOR . $filename;
//resize the file
list($o_width, $o_height, ) = getimagesize($realpath);
list($des_width, $des_height) = $this->getDestSize(array($o_width, $o_height));
$destination = $this->getDestName($fileinfo, array($des_width, $des_height));
$full_destination = $uploader->getFileBaseDir() . DIRECTORY_SEPARATOR . $destination;
$source = imagecreatefromstring(file_get_contents($realpath));
if (function_exists('imagescale')) {
$dest = imagescale($source, $des_width, $des_height);
if ($dest) {
$result = true;
} else {
$result = false;
}
} else {
$dest = imagecreatetruecolor($des_width, $des_height);
$result = imagecopyresampled($dest, $source, 0, 0, 0, 0, $des_width, $des_height, $o_width, $o_height);
}
imagedestroy($source);
if ($result) {
switch (strtolower($fileinfo->getExtension())) {
case 'jpg':
case 'jpeg':
default:
$result = imagejpeg($dest, $full_destination);
break;
case 'png':
$result = imagepng($dest, $full_destination);
break;
case 'gif':
$result = imagegif($dest, $full_destination);
break;
case 'bmp':
throw new Exception('不支持bmp文件');
break;
}
imagedestroy($dest);
if ($result) {
$info = new FileInfo($fileinfo->getName(), filesize($full_destination), $destination, $fileinfo->getType());
return $info;
}
return false;
}
return false;
}
示例6: scaleToHeight
function scaleToHeight($in_fn, $out_fn, $height)
{
if (!file_exists($in_fn)) {
throw new \Exception("file {$in_fn} does not exists");
}
$im = imagecreatefromjpeg($in_fn);
$ini_x_size = getimagesize($in_fn)[0];
$ini_y_size = getimagesize($in_fn)[1];
$new_y = $height;
$new_x = $new_y * $ini_x_size / $ini_y_size;
if (!($scaled_im = imagescale($im, $new_x, $new_y))) {
throw new \Exception("Scaling operation failed");
}
if (!imagejpeg($scaled_im, $out_fn, 100)) {
throw new \Exception("write of scaled image to {$out_fn} failed");
}
}
示例7: render
public function render()
{
$filename = '';
$path = '';
$width = 0;
$height = 0;
if ($this->request->input('path')) {
$filename = basename($this->request->input('path'));
}
if ($this->request->input('path')) {
$path = '/' . $this->request->input('path');
}
if ($this->request->input('x')) {
$width = $this->request->input('x');
}
if ($this->request->input('y')) {
$height = $this->request->input('y');
}
$image = $path;
$image_2 = '/images/cache/' . $width . 'x' . $height . '_' . $filename;
$new_image = Storage::get($image);
if (!Storage::directories(storage_path('app') . '/images/cache')) {
Storage::makeDirectory('/images/cache');
}
if ($width > 0) {
if (!Storage::exists($image_2)) {
switch (exif_imagetype(storage_path('app') . $image)) {
case 2:
$new_image = imagescale(imagecreatefromjpeg(storage_path('app') . $image), $width, $height, IMG_BICUBIC_FIXED);
imagejpeg($new_image, storage_path('app') . $image_2);
break;
case 3:
$new_image = imagescale(imagecreatefrompng(storage_path('app') . $image), $width, $height, IMG_BICUBIC_FIXED);
imagepng($new_image, storage_path('app') . $image_2);
break;
default:
break;
}
$new_image = Storage::get($image_2);
} else {
$new_image = Storage::get($image_2);
}
}
return (new Response($new_image, 200))->header('Content-Type', 'image/png');
}
示例8: uploadImageAction
public function uploadImageAction(Request $request): Response
{
$image = $request->files->get('image');
$filename = sha1(uniqid(mt_rand(), true)) . time();
$filePath = $filename . '.' . $image->guessExtension();
if ('png' == $image->guessExtension()) {
$imageSrc = imagecreatefrompng($image->getRealPath());
} else {
$imageSrc = imagecreatefromjpeg($image->getRealPath());
}
$imageScaled = imagescale($imageSrc, 800);
imagejpeg($imageScaled, $this->uploadDir.'/temp/'.$filePath);
$this->log->debug(sprintf('%s: image created %s',__CLASS__, $filePath));
return new JsonResponse(['image' => $filePath], 201);
}
示例9: run
public function run($template)
{
//Remove the whole string as the first result
array_shift($this->URLMatch);
//Get the database
$dbh = Engine::getDatabase();
//Get result ID
$resultID = $this->URLMatch[0];
//Check if the result is in the array and return results
$sql = "SELECT * FROM Results WHERE Result_ID IN (SELECT Result_ID FROM Result_History WHERE Result_ID= :result) LIMIT 1";
$stmt = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$stmt->execute(array(':result' => $resultID));
$result = $stmt->fetchObject('Result');
if ($result == false) {
exit;
}
//There's no result to give an image for
$result->Data = json_decode($result->Data, true);
$data = $result->Data;
$blueBackground = imagecreatefromstring(file_get_contents(__DIR__ . '/../public/images/share-background.png', "r"));
$friends = array_keys($data['interaction']);
$friend1 = imagecreatefromstring(file_get_contents(User::getAvatar($friends[0])));
//200,200 (width x height)
$friend2 = imagecreatefromstring(file_get_contents(User::getAvatar($friends[1])));
$friend3 = imagecreatefromstring(file_get_contents(User::getAvatar($friends[2])));
$gaussian = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0));
for ($i = 0; $i < 60; $i++) {
imageconvolution($friend1, $gaussian, 16, 0);
imageconvolution($friend2, $gaussian, 16, 0);
imageconvolution($friend3, $gaussian, 16, 0);
}
$graph = imagecreatefromstring(file_get_contents(__DIR__ . '/../public/images/white-logo-transparent-medium.png', "r"));
$foreground = imagecreatefromstring(file_get_contents(__DIR__ . '/../public/images/share-foreground.png', "r"));
imagecopy($blueBackground, $friend1, -50, 25, 0, 0, imagesx($friend1), imagesy($friend1));
imagecopy($blueBackground, $friend2, 150, 25, 0, 0, imagesx($friend2), imagesy($friend2));
imagecopy($blueBackground, $friend3, 350, 25, 0, 0, imagesx($friend3), imagesy($friend3));
$graph = imagescale($graph, imagesx($friend1) * 2);
imagecopy($blueBackground, $graph, 80, -20, 0, 0, imagesx($graph), imagesy($graph));
imagecopy($blueBackground, $foreground, 0, 0, 0, 0, imagesx($foreground), imagesy($foreground));
ob_clean();
ob_start();
header('Content-Type: image/png');
imagepng($blueBackground);
}
示例10: mergeImage
public static function mergeImage($src_a, $src_b)
{
$a = $src_a;
$b = $src_b;
$a = imagecreatefromstring($a);
$b = imagecreatefromstring($b);
$b = imagescale($b, imagesx($a) / 4);
Utils::imagecopymerge_alpha($a, $b, imagesx($a) / 2 - imagesx($b) / 2, imagesy($a) / 100 * 10, 0, 0, imagesx($b), imagesy($b), 100);
imagesavealpha($a, true);
// php u fuckng suck
ob_start();
imagepng($a);
$contents = ob_get_contents();
ob_end_clean();
//
imagedestroy($a);
imagedestroy($b);
return $contents;
}
示例11: resize_image
protected function resize_image($image, $width, $height)
{
$ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
if (!preg_match('/(jpg|jpeg|png|gif)/', $ext)) {
$src = imagecreatefromstring(file_get_contents($image));
unlink($image);
$image = sprintf("%s/%s.png", pathinfo($image, PATHINFO_DIRNAME), pathinfo($image, PATHINFO_FILENAME));
imagepng($src, $image);
imagedestroy($src);
}
list($oWidth, $oHeight) = getimagesize($image);
if ($oWidth > $width || $oHeight > $height) {
$ratio = min($width / $oWidth, $height / $oHeight);
$src = imagecreatefromstring(file_get_contents($image));
$dst = imagescale($src, $oWidth * $ratio, $oHeight * $ratio, IMG_BICUBIC);
call_user_func(preg_match('/jpeg|jpg/', $ext) ? 'imagejpeg' : (preg_match('/gif/', $ext) ? 'imagegif' : 'imagepng'), $dst, $image);
imagedestroy($src);
imagedestroy($dst);
}
return $image;
}
示例12: imageUpload
/**
* The method by which images are uploaded to our servers
*
* @throws \RuntimeException when the user did not have the authority to add an image
* @throws \InvalidArgumentException when filetype is not supported
* @throws \Exception when another error occurs
**/
public function imageUpload()
{
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
if (empty($_SESSION["profile"]) === true) {
throw new \RuntimeException("Please log in or sign up", 401);
}
if ($_SESSION["profile"]->getProfileId() !== $this->imageProfileId) {
throw new \RuntimeException("We could not upload your image, as your account did not match the account the image would have been placed under. We didn't even think that was possible.", 401);
}
$maximumWidth = 2048;
$maximumHeight = 2048;
$validExts = ["jpeg", "jpg", "gif", "png"];
$validFormat = ["image/jpeg", "image/jpg", "image/gif", "image/png"];
$name = $_FILES["file"]["name"];
$tmp = explode(".", $name);
$extension = strtolower(end($tmp));
$type = $_FILES["file"]["type"];
$imagePath = $_FILES["file"]["tmp_name"];
if (in_array($type, $validFormat) === false || in_array($extension, $validExts) === false) {
throw new \InvalidArgumentException("File was not of correct type", 418);
// tea earl grey hot
}
$identificationOfImage = $_SESSION["profile"]->getProfileEmail() . $this->imageId;
$tempName = hash("ripemd160", $identificationOfImage) . ".";
$imageSizes = getimagesize($imagePath);
$widthRatio = $maximumWidth / $imageSizes[0];
$heightRatio = $maximumHeight / $imageSizes[1];
switch ($extension) {
case "jpeg":
$tempImage = imagecreatefromjpeg($imagePath);
break;
case "jpg":
$tempImage = imagecreatefromjpeg($imagePath);
break;
case "gif":
$tempImage = imagecreatefromgif($imagePath);
break;
case "png":
$tempImage = imagecreatefrompng($imagePath);
break;
default:
throw new \InvalidArgumentException("File was not of correct type", 418);
break;
}
if (!($imageSizes[0] <= $maximumWidth && $imageSizes[1] <= $maximumHeight)) {
if ($heightRatio * $imageSizes[0] < $maximumWidth) {
$tempImage = imagescale($tempImage, $heightRatio * $imageSizes[0], $maximumHeight);
} else {
$tempImage = imagescale($tempImage, $maximumWidth, $widthRatio * $imageSizes[1]);
}
}
if ($extension === "gif") {
$tempName = $tempName . "gif";
$fileLocation = "/var/www/html/public_html/jpegery/content/" . $tempName;
$savedImage = imagegif($tempImage, $fileLocation);
$this->setImageType("image/gif");
} else {
$tempName = $tempName . "jpeg";
$fileLocation = "/var/www/html/public_html/jpegery/content/" . $tempName;
$savedImage = imagejpeg($tempImage, $fileLocation);
$this->setImageType("image/jpeg");
}
$this->setImageFileName($fileLocation);
if ($savedImage === false) {
throw new \Exception("Something went wrong in uploading your image.", 400);
}
}
示例13: define
define('MODE_A4R4G4B4', 'a4r4g4b4');
define('COMPRESSION_OFF', 'off');
$options = options();
list($width, $height, $type) = getimagesize($options->input);
switch ($type) {
case IMAGETYPE_JPEG:
$image = imagecreatefromjpeg($options->input);
break;
case IMAGETYPE_PNG:
$image = imagecreatefrompng($options->input);
break;
default:
error(sprintf("Unsupported file type '%s'", $options->input));
}
$image = imagescale($image, $options->width, $options->height);
$output = fopen($options->output, 'wb');
if (false === $output) {
error(sprintf("Can't open output file '%s'", $options->output));
}
//
// Image's information
//
// 64-bytes image's name
fwrite($output, pack('a63x', $options->name));
// 2-bytes BE width and height
fwrite($output, pack('n', $options->width));
fwrite($output, pack('n', $options->height));
// 2-bytes color's mode and compression's mode
switch ($options->mode) {
case MODE_A4R4G4B4:
示例14: resize
/**
* @param int $width
* @param int $height
*
* @return static
*/
public function resize($width, $height)
{
if (version_compare(PHP_VERSION, '5.5.0') < 0) {
$image = imagecreatetruecolor($width, $height);
imagealphablending($image, false);
imagesavealpha($image, true);
imagecopyresampled($image, $this->_image, 0, 0, 0, 0, $width, $height, $this->_width, $this->_height);
} else {
$image = imagescale($this->_image, $width, $height);
}
imagedestroy($this->_image);
$this->_image = $image;
$this->_width = imagesx($image);
$this->_height = imagesy($image);
return $this;
}
示例15: dirname
<?php
include dirname(__FILE__) . '/_init.php';
$im = imagecreatefromjpeg('images/mutzig.jpg');
$im1 = imagescale($im, 100, 100, IMAGE_EX_SCALE_PAD);
imagejpeg($im1, 'output/scale-pad-1.jpg');
$im2 = imagescale($im, 1000, 1000, IMAGE_EX_SCALE_PAD);
imagejpeg($im2, 'output/scale-pad-2.jpg');