login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Uploadify resize

Offline cowb - 24/03/2011 16:14 (laatste wijziging 30/03/2011 17:28)
Avatar van cowbLid Hi all,

Ik ben mijn uploadify script wat aan het uitbreiden. En ik zou graag hebben dat mijn afbeelding wat verkleind wordt na het uploaden.
Maar vreemd genoeg, gebeurt dit niet...
Mijn afbeelding wordt geupload en daarna wordt de bestandsnaam in de db opgeslagen. Maar het resize gedeelte krijg ik niet aan de praat. Weet iemand hoe dat zou komen? Aub!


  1. <?php
  2. include("config.php");
  3. $id = $_REQUEST['id'];
  4.  
  5.  
  6. if (!empty($_FILES)) {
  7. $tempFile = $_FILES['Filedata']['tmp_name'];
  8. $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
  9. $targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
  10.  
  11.  
  12. move_uploaded_file($tempFile,$targetFile);
  13.  
  14. $datum = time();
  15. $query_ = "INSERT INTO fotos (ID, album_ID, path, datum) VALUES ('', '".$id."', 'afbeeldingen/".$_FILES['Filedata']['name']."', '".$datum."')";
  16. mysql_query($query_) or die (mysql_error());
  17.  
  18. $ext = strtolower(strrchr(basename("afbeeldingen/".$_FILES['Filedata']['name']),'.'));
  19. $filename = "afbeeldingen/".$_FILES['Filedata']['name'];
  20. $width = 600;
  21. $height = 600;
  22. list($width_orig, $height_orig) = getimagesize($filename);
  23. if (!isset($width_orig) OR !isset($height_orig)){
  24. $width_orig = 640;
  25. $height_orig = 480;
  26. }
  27. if (($width_orig < $width) && ($height_orig < $height )){
  28. //Klein plaatje
  29. $width = $width_orig ;
  30. $height = $height_orig;
  31. }else{
  32. $ratio_orig = $width_orig/$height_orig;
  33. if ($width/$height > $ratio_orig) {
  34. $width = $width*$ratio_orig;
  35. } else {
  36. $height = $width/$ratio_orig;
  37. }
  38. }
  39. $image_p = imagecreatetruecolor($width, $height);
  40. switch ($ext){
  41. case ".gif":
  42. $image = imagecreatefromgif($filename);
  43. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
  44. imagegif($image_p, 'afbeeldingen/'.$_FILES['Filedata']['name']);
  45. break;
  46. case ".png":
  47. $image = imagecreatefrompng($filename);
  48. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
  49. imagepng($image_p, 'afbeeldingen/'.$_FILES['Filedata']['name']);
  50. break;
  51. default:
  52. $image = imagecreatefromjpeg($filename);
  53. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
  54. imagejpeg($image_p, 'afbeeldingen/'.$_FILES['Filedata']['name'], 75);
  55. }
  56.  
  57. imagedestroy($image_p);
  58.  
  59.  
  60. echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
  61.  
  62. }
  63. ?>

2 antwoorden

Gesponsorde links
Offline Kwarde - 05/04/2011 22:09
Avatar van Kwarde Nieuw lid Wil je dat hij gewoon kleiner wordt, of wil je dat zodat hij gewoon kleiner wordt weergeven?
Je kan met CSS nl. heel simpel de 'max-width' en 'max-length' gebruiken.
Offline RickBouman - 17/04/2011 20:07
Avatar van RickBouman Nieuw lid GD Libary kan je hiervoor ook gebruiken?
Gesponsorde links
Je moet ingelogd zijn om een reactie te kunnen posten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.193s