本文整理汇总了PHP中resize_image函数的典型用法代码示例。如果您正苦于以下问题:PHP resize_image函数的具体用法?PHP resize_image怎么用?PHP resize_image使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resize_image函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_video_prev
function get_video_prev($id, $size)
{
$size = explode('x', strtolower($size));
$size[0] = prev_size_c(@$size[0]);
$size[1] = prev_size_c(@$size[1]);
if (!$size[1] || !$size[0]) {
return false;
}
$pf = ROOT_PATH . '/tmp/attach_thumb/att-' . $id . '-' . $size[0] . '-' . $size[1] . '.jpg';
if (file_exists($pf)) {
return $pf;
}
$pm = ROOT_PATH . '/tmp/attach_thumb/att-' . $id . '-video.jpg';
# Exists master-copy?
if (!file_exists($pm)) {
$r = array();
exec('/usr/local/bin/ffmpeg -i ' . ROOT_PATH . '/uploads/att-' . $id . '.dat -an -ss 5 -r 1 -vframes 1 -s 640x480 -y -f mjpeg ' . $pm, $r);
}
if (!file_exists($pm)) {
return $pm;
}
$res = resize_image($pm, $size[0], $size[1]);
@copy($res, $pf);
return $res;
}
示例2: get_thumb_image_url
/**
* Returns thumbnail size image url.
* @since 1.0
*
* @return string
*/
protected function get_thumb_image_url()
{
$url = $this->image_url;
if ($url) {
return resize_image($url, 120, 120);
}
return;
}
示例3: save_sized_image
function save_sized_image($original, $key, $size, $folder)
{
$file = $folder . "/" . $key . ".jpg";
$file_path = IMAGES_DIR . "/" . $file;
resize_image($original, $size, $file_path);
if (STORAGE_STRATEGY == 's3') {
$input = S3::inputFile($file_path);
S3::putObject($input, S3_BUCKET, $file, S3::ACL_PUBLIC_READ);
}
}
示例4: create_thumbnail
function create_thumbnail($filename, $thumbdir = 'sm', $width = 32, $quality = 90)
{
try {
$fd = dirname($filename) . '/' . $thumbdir;
@mkdir($fd);
$name = basename($filename);
$thumb = $fd . '/' . $name;
return resize_image($filename, $thumb, $width, $quality);
} catch (Exception $e) {
}
return false;
}
示例5: upload_song
function upload_song($tempFile, $title = null, $artist = null, $genre = null, $rating = null)
{
global $db;
$extension = strtolower(pathinfo($tempFile, PATHINFO_EXTENSION));
$id = make_song_id($title, $tempFile);
if ($id === false) {
return array('success' => false, 'message' => "Duplicate File");
}
if (!$title || !$artist) {
$result = get_song_info($tempFile, $extension);
if (!$title) {
$title = $result['title'];
}
if (!$artist) {
$artist = $result['artist'];
}
}
if (!$rating) {
$rating = 2.5;
}
$i = 1;
$uploadFile = sanitize_file_name($title) . '.' . $extension;
while (file_exists(__FILES__ . $uploadFile)) {
$uploadFile = sanitize_file_name($title) . $i . '.' . $extension;
$i++;
}
switch ($extension) {
case 'txt':
case 'chopro':
case 'pdf':
// NO PROCESSING
if (!copy($tempFile, __FILES__ . $uploadFile)) {
return array('success' => false, 'message' => "failed to copy {$tempFile} to {$uploadFile}");
}
break;
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
// RESIZE
resize_image($tempFile, __FILES__ . $uploadFile, $extension, MAX_FILE_W, MAX_FILE_H);
break;
default:
return array('success' => false, 'message' => "file extension '." . $extension . "'not recognized");
return;
}
$query = "INSERT INTO music (songID, location, title, artist, genre, rating, views, uploaded)";
$query .= " VALUES ( '" . $db->escape($id) . "','" . $db->escape($uploadFile) . "','";
$query .= $db->escape($title) . "','" . $db->escape($artist) . "','" . $db->escape($genre) . "'," . $db->escape($rating) . ",0," . time() . " )";
$result = $db->query($query);
unlink($tempFile);
return array('success' => true, 'message' => $title . " successfully uploaded!");
}
示例6: process_image
function process_image($dir, $filename)
{
// Set up the variables
$i = strrpos($filename, '.');
$image_name = substr($filename, 0, $i);
$ext = substr($filename, $i);
// Set up the read path
$image_path = $dir . $filename;
// Set up the write paths
$image_path_m = $dir . $image_name . '_m' . $ext;
$image_path_s = $dir . $image_name . '_s' . $ext;
// Create an image that's a maximum of 400x300 pixels
resize_image($image_path, $image_path_m, 250, 250);
// Create a thumbnail image that's a maximum of 100x100 pixels
resize_image($image_path, $image_path_s, 120, 100);
}
示例7: process_image
function process_image($dir, $filename)
{
// Set up the variables
$dir = $dir . DIRECTORY_SEPARATOR;
$i = strrpos($filename, '.');
$image_name = substr($filename, 0, $i);
$ext = substr($filename, $i);
// Set up the read path
$image_path = $dir . DIRECTORY_SEPARATOR . $filename;
// Set up the write paths
$image_path_400 = $dir . $image_name . '_400' . $ext;
$image_path_100 = $dir . $image_name . '_100' . $ext;
// Create an image that's a maximum of 400x300 pixels
resize_image($image_path, $image_path_400, 400, 300);
// Create a thumbnail image that's a maximum of 100x100 pixels
resize_image($image_path, $image_path_100, 100, 100);
}
示例8: save_image
private function save_image($temp_file)
{
//generate a random ID for this image
$file_id = md5(uniqid(rand(), true));
array_push($this->image_ids, $file_id);
//copy original
$original_file_name = IMAGES_DIR . "/original/" . $file_id . ".jpg";
$moved = move_uploaded_file($temp_file, $original_file_name);
if (!$moved) {
$this->add_warning("Sorry something went wrong saving your image");
} else {
//save large
resize_image($original_file_name, IMAGE_LARGE_SIZE, IMAGES_DIR . "/large/" . $file_id . ".jpg");
//save medium
resize_image($original_file_name, IMAGE_MEDIUM_SIZE, IMAGES_DIR . "/medium/" . $file_id . ".jpg");
//save thumbnail
resize_image($original_file_name, IMAGE_THUMBNAIL_SIZE, IMAGES_DIR . "/thumbnail/" . $file_id . ".jpg");
}
}
示例9: cacheImages
public function cacheImages($images)
{
foreach ($images as $key => $url) {
if (file_exists($this->getImagesCachePath($url))) {
# exclude images in already in cache
unset($images[$key]);
}
}
if (empty($images)) {
return true;
}
$mh = curl_multi_init();
$cHandlers = array();
foreach ($images as $url) {
$cHandlers[$url] = curl_init();
curl_setopt($cHandlers[$url], CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cHandlers[$url], CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($cHandlers[$url], CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($cHandlers[$url], CURLOPT_URL, $url);
curl_setopt($cHandlers[$url], CURLOPT_RETURNTRANSFER, true);
curl_setopt($cHandlers[$url], CURLOPT_TIMEOUT, 30);
curl_multi_add_handle($mh, $cHandlers[$url]);
}
$running = NULL;
do {
usleep(10000);
curl_multi_exec($mh, $running);
} while ($running > 0);
foreach ($cHandlers as $url => $ch) {
$imgData = curl_multi_getcontent($ch);
curl_multi_remove_handle($mh, $ch);
$cachePath = $this->getImagesCachePath($url);
$pathinfo = pathinfo($cachePath);
$tmpfile = cfg()->tmpDir . "/" . uniqid() . "." . $pathinfo['extension'];
if (file_put_contents($tmpfile, $imgData)) {
resize_image($tmpfile, $cachePath, cfg()->ali->cache->images->resize);
unlink($tmpfile);
}
}
}
示例10: get_cached_thumbnail_link
function get_cached_thumbnail_link($width, $link, $forced = false)
{
global $thumbnail_directory;
// $link をローカルファイルのパスに変換
$src = link_to_path($link);
// $width, $srcをチェック
if (!preg_match("/^\\d{1,4}\$/", $width) || !file_exists($src)) {
// 不正なら空文字列を返す
return "";
}
//thumbnailのパスを決める
$thumbnail_path = thumbnail_path($width, $src);
if (!$forced && file_exists($thumbnail_path) && stat($thumbnail_path)["mtime"] > stat($src)["mtime"]) {
// $forced=falseであり、かつ、
// キャッシュされているサムネイルが既に存在し、かつ、
// それが新しければ何もしない
} else {
// 上記以外の場合、キャッシュを生成する
resize_image($width, $src, $thumbnail_path);
}
// キャッシュへのhtmlリンクを返す
return path_to_link($thumbnail_path);
}
示例11: upload_file
function upload_file()
{
if (!isset($this->file) || is_null($this->file['tmp_name']) || $this->file['name'] == '') {
//Check File //Chequea sl archivo
//$this->file['name']=$defecto;// = "Archivo no fue subido";
$this->ErrorMsg = "Archivo no fue subido";
return false;
}
if ($this->file['size'] > $this->maxsize) {
//Check Size
$this->ErrorMsg = "El Archivo Excede el Tamaño permitido de {$this->maxsize} bytes";
return false;
}
if (count($this->allowtypes) > 0 && !in_array($this->file['type'], $this->allowtypes) || count($this->deniedtypes) > 0 && in_array($this->file['type'], $this->deniedtypes)) {
//Check Type //Chequea el tipo de archivo
$this->ErrorMsg = "Tipo de Archivo '." . file_extension($this->file['name']) . " -- {$this->file['type']}' No Permitido.";
return false;
}
if (!$this->newfile) {
$this->newfile = substr(basename($this->file['name']), 0, strrpos($this->file['name'], '.'));
}
//No new name specified, default to old name
$uploaddirtemp = upload_dir($this->uploaddir);
//Create Upload Dir
move_uploaded_file($this->file['tmp_name'], $uploaddirtemp . $this->newfile . "." . file_extension($this->file['name']));
//Move Uploaded File
if ($maxwidth == "" && ($maxheight = "")) {
//No need to resize the image, user did not specify to reszie
$this->final = "." . $this->uploaddir . $this->newfile . "." . file_extension($this->file['name']);
return true;
}
//User is going to resize the image
resize_image("." . $this->uploaddir . $this->newfile . "." . file_extension($this->file['name']), $this->maxwidth, $this->maxheight, $this->scale, $this->relscale, $this->jpegquality);
$this->final = "." . $this->uploaddir . $this->newfile . "." . file_extension($this->file['name']);
return true;
//Hooray!
}
示例12: array
$submitnews_filearray = array();
foreach ($uploaded as $c => $v) {
if (varset($uploaded[$c]['error'], 0) != 0) {
$submitnews_error = TRUE;
$message = handle_upload_messages($uploaded);
} else {
if (isset($uploaded[$c]['name']) && isset($uploaded[$c]['type']) && isset($uploaded[$c]['size'])) {
$filename = $uploaded[$c]['name'];
$filetype = $uploaded[$c]['type'];
$filesize = $uploaded[$c]['size'];
$fileext = substr(strrchr($filename, "."), 1);
$today = getdate();
$submitnews_file = USERID . "_" . $today[0] . "_" . $c . "_" . str_replace(" ", "_", substr($submitnews_title, 0, 6)) . "." . $fileext;
if (is_numeric($pref['subnews_resize']) && $pref['subnews_resize'] > 30 && $pref['subnews_resize'] < 5000) {
require_once e_HANDLER . 'resize_handler.php';
if (!resize_image(e_UPLOAD . $filename, e_UPLOAD . $submitnews_file, $pref['subnews_resize'])) {
rename(e_UPLOAD . $filename, e_UPLOAD . $submitnews_file);
}
} elseif ($filename) {
rename(e_UPLOAD . $filename, e_UPLOAD . $submitnews_file);
}
}
}
if ($filename && file_exists(e_UPLOAD . $submitnews_file)) {
$submitnews_filearray[] = $submitnews_file;
}
}
}
}
if ($submitnews_error === FALSE) {
$sql->insert("submitnews", "0, '{$submitnews_user}', '{$submitnews_email}', '{$submitnews_title}', '" . intval($_POST['cat_id']) . "', '{$submitnews_item}', '" . time() . "', '{$ip}', '0', '" . implode(',', $submitnews_filearray) . "' ");
示例13: cpg_die
cpg_die(ERROR, $lang_db_input_php['err_invalid_img'], __FILE__, __LINE__, true);
// JPEG and PNG only are allowed with GD
//} elseif ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($CONFIG['thumb_method'] == 'gd1' || $CONFIG['thumb_method'] == 'gd2')) {
} elseif ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && $CONFIG['GIF_support'] == 0) {
@unlink($uploaded_pic);
cpg_die(ERROR, $lang_errors['gd_file_type_err'], __FILE__, __LINE__, true);
// *** NOT NEEDED CHECK DONE BY 'is_image'
// Check image type is among those allowed for ImageMagick
//} elseif (!stristr($CONFIG['allowed_img_types'], $IMG_TYPES[$imginfo[2]]) && $CONFIG['thumb_method'] == 'im') {
//@unlink($uploaded_pic);
//cpg_die(ERROR, sprintf($lang_db_input_php['allowed_img_types'], $CONFIG['allowed_img_types']), __FILE__, __LINE__);
// Check that picture size (in pixels) is lower than the maximum allowed
} elseif (max($imginfo[0], $imginfo[1]) > $CONFIG['max_upl_width_height']) {
if (USER_IS_ADMIN && $CONFIG['auto_resize'] == 1 || !USER_IS_ADMIN && $CONFIG['auto_resize'] > 0) {
//resize_image($uploaded_pic, $uploaded_pic, $CONFIG['max_upl_width_height'], $CONFIG['thumb_method'], $imginfo[0] > $CONFIG['max_upl_width_height'] ? 'wd' : 'ht');
resize_image($uploaded_pic, $uploaded_pic, $CONFIG['max_upl_width_height'], $CONFIG['thumb_method'], $CONFIG['thumb_use']);
} else {
@unlink($uploaded_pic);
cpg_die(ERROR, sprintf($lang_db_input_php['err_fsize_too_large'], $CONFIG['max_upl_width_height'], $CONFIG['max_upl_width_height']), __FILE__, __LINE__);
}
}
// Image is ok
}
// Upload is ok
// Create thumbnail and internediate image and add the image into the DB
$result = add_picture($album, $filepath, $picture_name, 0, $title, $caption, $keywords, $user1, $user2, $user3, $user4, $category, $raw_ip, $hdr_ip, (int) $_POST['width'], (int) $_POST['height']);
if (!$result) {
@unlink($uploaded_pic);
cpg_die(CRITICAL_ERROR, sprintf($lang_db_input_php['err_insert_pic'], $uploaded_pic) . '<br /><br />' . $ERROR, __FILE__, __LINE__, true);
} elseif ($PIC_NEED_APPROVAL) {
pageheader($lang_info);
示例14: dirname
<?php
$dir = dirname(__FILE__);
//echo $dir . "<br>";
$folders = scandir($dir);
foreach ($folders as $categorias) {
//echo $categorias . "<br>";
if ($categorias != "." && $categorias != ".." && $categorias != "index.php" && $categorias != "thumb.jpg" && $categorias != "all-thumb.gif" && $categorias != "cs-close.png") {
$cat = $dir . "/" . $categorias;
//echo $cat."<br/>";
$list = scandir($cat);
//create thumbs
createThumbs($dir . "/" . $categorias . "", $dir . "/" . $categorias . "/thumbs", 75);
//reducir
resize_image($dir . "/" . $categorias . "", $dir . "/" . $categorias . "", 650);
/*foreach ( $list as $imagen ) {
if ($imagen != "." && $imagen != ".." && $imagen != "index.php" && $imagen != "thumb.jpg") {
// echo $imagen;
//echo $dir . "/" . $categorias."/".$imagen."<br/>";
//echo "se crearon los archivos.<br/>";
}
}*/
}
}
function createThumbs($pathToImages, $pathToThumbs, $thumbWidth)
{
// open the directory
$dir = opendir($pathToImages);
if (!is_dir($pathToThumbs)) {
echo "se creo {$pathToThumbs}<br/>";
if (!mkdir($pathToThumbs, 0777, true)) {
示例15: error_log
$ds = DIRECTORY_SEPARATOR;
//1
$storeFolder = 'uploads';
//2
$campaign_id = $_POST['campaign_id'];
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
//3
error_log($tempFile, 3, 'pic_bug.txt');
$targetPath = dirname(__FILE__) . $ds . $storeFolder . $ds;
//4
error_log("-------", 3, 'pic_bug.txt');
$targetFile = $targetPath . $_FILES['file']['name'];
//5
error_log($targetFile, 3, 'pic_bug.txt');
$img = resize_image($tempFile, 800, 800);
$fakepath = "http://localhost:8888/carvertise/gallery/admin/uploads/" . $_FILES['file']['name'];
$carvertisepath = "http://52.23.43.247/gallery/admin/uploads/" . $_FILES['file']['name'];
if (!imagejpeg($img, 'uploads/' . $_FILES['file']['name'])) {
error_log("imagejpeg", 3, 'pic_bug.txt');
echo "Failed to save the cropped image file";
}
//move_uploaded_file($img,$targetFile); //6
$query = "INSERT INTO picture (campaign_id,url) VALUES ('{$campaign_id}','{$carvertisepath}')";
if (mysqli_query($conn, $query)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
}
function resize_image($file, $w, $h, $crop = FALSE)