<?php
$images = $_FILES["userfile"]["tmp_name"];
$new_images = "small_".$_FILES["userfile"]["name"];
$target = "large/".$new_images;
$width=314; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round($width*$size[1]/$size[0]);
$images_orig = ImageCreateFromJPEG($images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1,
$height+1, $photoX, $photoY);
ImageJPEG($images_fin,"uploads/".$new_images);
ImageJPEG($images_orig,"large/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
?>
我一直在这工作几个小时。我希望将原始图像存储到“大”目录中,并将调整大小的图像存储到“上传”,但不会存储大图像。调整大小的图像存储得很好。我究竟做错了什么?我已经尝试了十几种不同的方式,这就是我放弃的地方。
答案 0 :(得分:2)
所以我知道这是旧的,但这是我使用你的代码的答案...如果你先将原始文件移动到目录。您可以使用该文件重新调整大小,然后存储在您想要的位置。
$ year,$ renamefiledash和$ ChangeSecond vars来自我自己的表格。您可以将文件命名为您喜欢的文件
move_uploaded_file($_FILES["file"]["tmp_name"],
$_SERVER['DOCUMENT_ROOT'].'/downloads/media/'.$year.'/'.$renameFileDash.'.'.$changeSecond);
$images = $_SERVER['DOCUMENT_ROOT'].'/downloads/media/'.$year.'/'.$renameFileDash.'.'.$changeSecond;
$width=618; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round($width*$size[1]/$size[0]);
$images_orig = ImageCreateFromJPEG($images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1,
$height+1, $photoX, $photoY);
ImageJPEG($images_fin,$_SERVER['DOCUMENT_ROOT'].'/images/media-archive/media-thumbs/'.$renameFileDash.'.'.$changeSecond);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
答案 1 :(得分:0)
我发现这个php类非常有用: PHP image resize class
一个小例子:
include("path/to/your/class/folder/resize_class.php");
$resizeObj = new resize('path/to/your/images/folder/name_of_image_recently_uploaded.jpg');
$resizeObj -> resizeImage(150, 100, 0);
$resizeObj -> saveImage('path/to/your/images/thumb/folder/name_of_image_recently_uploaded.jpg', 100);
希望它有所帮助!