本文整理汇总了PHP中SimpleImage::best_fit方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleImage::best_fit方法的具体用法?PHP SimpleImage::best_fit怎么用?PHP SimpleImage::best_fit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleImage
的用法示例。
在下文中一共展示了SimpleImage::best_fit方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Создание новости
*/
public function create()
{
if (!User::isAdmin()) {
App::abort('403');
}
if (Request::isMethod('post')) {
$news = new News();
$news->category_id = Request::input('category_id');
$news->user_id = User::get('id');
$news->title = Request::input('title');
$news->slug = '';
$news->text = Request::input('text');
$image = Request::file('image');
if ($image && $image->isValid()) {
$ext = $image->getClientOriginalExtension();
$filename = uniqid(mt_rand()) . '.' . $ext;
if (in_array($ext, ['jpeg', 'jpg', 'png', 'gif'])) {
$img = new SimpleImage($image->getPathName());
$img->best_fit(1280, 1280)->save('uploads/news/images/' . $filename);
$img->best_fit(200, 200)->save('uploads/news/thumbs/' . $filename);
}
$news->image = $filename;
}
if ($news->save()) {
if ($tags = Request::input('tags')) {
$tags = array_map('trim', explode(',', $tags));
foreach ($tags as $tag) {
$tag = Tag::create(['name' => $tag]);
$tag->create_news_tags(['news_id' => $news->id]);
}
}
App::setFlash('success', 'Новость успешно создана!');
App::redirect('/' . $news->category->slug . '/' . $news->slug);
} else {
App::setFlash('danger', $news->getErrors());
App::setInput($_POST);
}
}
$categories = Category::getAll();
App::view('news.create', compact('categories'));
}
示例2: image
/**
* Загрузка фото в профиль
*/
public function image()
{
if (!Request::ajax() || !User::check()) {
App::redirect('/');
}
// Удаление и размер
$image = Request::file('image');
if ($image->isValid()) {
$ext = $image->getClientOriginalExtension();
if (in_array($ext, ['jpeg', 'jpg', 'png', 'gif'])) {
$filename = uniqid(mt_rand()) . '.' . $ext;
$user = User::get();
$user->deleteImages();
$img = new SimpleImage($image->getPathName());
$img->best_fit(1280, 1280)->save('uploads/users/photos/' . $filename);
$img->best_fit(200, 200)->save('uploads/users/thumbs/' . $filename);
$img->thumbnail(48, 48)->save('uploads/users/avatars/' . $filename);
$user->avatar = $filename;
if ($user->save()) {
exit(json_encode(['status' => 'uploaded']));
} else {
exit(json_encode(['status' => 'nosave']));
}
} else {
exit(json_encode(['status' => 'invalid']));
}
}
}
示例3: getimagesize
$imageinfo = getimagesize($_FILES['userfile']['tmp_name']);
if ($imageinfo['mime'] != 'image/png' && $imageinfo['mime'] != 'image/jpeg') {
if ($_FILES['userfile']['error'] == '4') {
echo "Извините, но только jpeg и gif файлы\n";
}
if ($_FILES['userfile']['error'] == '1') {
echo "Слишком большой файл!";
}
if ($_FILES['userfile']['error'] == '0') {
echo "Файл загружен!";
}
exit;
}
$uploaddir = 'images/big/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "Файл загружен.\n</br><a href=\"_add.php?new_pic=" . $_FILES['userfile']['name'] . "\">Редактирование тэгов изображеня</a>";
echo "<a href=\"backend.php?new_pic=" . $_FILES['userfile']['name'] . ">ggfhfghfgho</a>dfgfdg";
echo "dsfsdfjsdhfhsdhsjhfjkshfjhsf";
//меняем регистр на мелкий т.к. simpleimage не переваривает .JPG$_FILES['userfile']['name']=mb_convert_case($_FILES['userfile']['name'], MB_CASE_LOWER);
$img = new SimpleImage('images/big/' . $_FILES['userfile']['name']);
$img->best_fit(950, 950)->save('images/big/' . $_FILES['userfile']['name']);
$img->best_fit(950, 950)->square_crop(150)->save('images/small/' . $_FILES['userfile']['name']);
} else {
echo "File uploading failed.\n";
}
echo "<a href=\"backend.php?new_pic=" . $_FILES['userfile']['name'] . "stra</a>";
//echo "<script> window.location = 'http://127.0.0.1/ls2013/gallery/_add.php?image=".$_FILES['userfile']['name']."'</script>";
} else {
echo "access denied";
}
示例4: basename
}
if ($_FILES['userfile']['error'] == '0') {
echo "Файл загружен!";
}
exit;
}
$uploaddir = 'image/600/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
//echo "Файл загружен.\n</br><a href=\"backend.php?new_pic=".$_FILES['userfile']['name']."\">ggfhfghfgho</a>";
//echo "<a href=\"backend.php?new_pic=".$_FILES['userfile']['name'].">ggfhfghfgho</a>dfgfdg";
// echo "dsfsdfjsdhfhsdhsjhfjkshfjhsf";
//меняем регистр на мелкий т.к. simpleimage не переваривает .JPG
$_FILES['userfile']['name'] = mb_convert_case($_FILES['userfile']['name'], MB_CASE_LOWER);
$img = new SimpleImage('image/600/' . $_FILES['userfile']['name']);
$img->best_fit(250, 562)->save('image/' . $_FILES['userfile']['name']);
$img->best_fit(80, 180)->save('image/80/' . $_FILES['userfile']['name']);
echo "Загружено";
} else {
echo "File uploading failed.\n";
}
//echo $category;
//echo "<a href=\"backend.php?new_pic=".$_FILES['userfile']['name'];
// echo "<script>
// window.location = 'http://127.0.0.1/ls2013/gallery/_add.php?image=".$_FILES['userfile']['name']."'
// </script>";
?>
示例5: resizeImage
function resizeImage($source_image, $target_image, $width = 0, $height = 0, $best_fit = false)
{
$SimpleImage = new SimpleImage($source_image);
if ($best_fit) {
$SimpleImage->best_fit($width, $height)->save($target_image, 100);
} else {
if (!$width && !$height) {
$SimpleImage->save($target_image);
} elseif ($SimpleImage->get_width() >= $width) {
$SimpleImage->fit_to_width($width)->crop(0, 0, $width, $SimpleImage->get_height() > $height ? $height : $SimpleImage->get_height())->save($target_image);
} elseif ($SimpleImage->get_height() >= $height) {
$SimpleImage->fit_to_width($height)->crop(0, 0, $SimpleImage->get_width() > $width ? $width : $SimpleImage->get_width(), $height)->save($target_image);
} else {
$SimpleImage->best_fit($width, $height)->save($target_image);
}
}
}