This question already has an answer here:
- Resize/crop/pad a picture to a fixed size 11 answers
i'm trying to resize an image and save it to my server. i figured out how to save the image from a URL, but then I want to resize the image and save it in the exact same location. this is the script i'm currently using. it's saving the image but the resize isn't working.
$cover = $_POST['cover'];
$title = $_POST['title'];
$artist = $_POST['artist'];
$date = date('Y-m-d', strtotime($_POST['date']));
$url = $cover;
$save_name = $artist."_".$title.".jpg";
$save_name = str_replace(' ','',$save_name);
$save_directory = $_ENV["DOCUMENT_ROOT"]."/albums/images/art/";
if(is_writable($save_directory)) {
file_put_contents($save_directory . $save_name, file_get_contents($url));
} else {
exit("Failed to write to directory ".$save_directory);
}
$location = "http://www.MYURL.com/albums/images/art/".$save_name;
$sql = "INSERT INTO albums (artist, title, date, cover) VALUES ('".$artist."', '".$title."', '".$date."', '".$location."')";
mysql_query($sql);
include("resize-class.php");
$resizeObj = new resize($location);
$resizeObj -> resizeImage(150, 150, 'exact');
$resizeObj -> saveImage($save_name, 100);
i'm using resize-class.php which i thought would make things easy but it's not working. i think i might be confusing my resize path or output path but i'm not entirely sure. any tips would be really helpful
</div>