Image Crop

so jetzt habe ich fast alle Probleme die ich hatte gelöst,
nur jetzt habe ich noch eine kleinigkeit, die mich Persönlich stört. undzwar wenn ich z.B. ein Panoramabild ausgewählt und mir darauf hin dann überlege, ne ich möchte doch ein andere nehmen. Dann passiert folgendes. Die Form des zuvor ausgwählten Bild wird übernommen und das neue bild darauf angepasst, sprich das Bild wird gestaucht. Jedoch klicke ich das weg und wähle es direkt wieder neu aus, wird es mir direkt proportional angezeigt auf der wünschten größe. Habt ihr eine Idee woran es liegen könnte? vllt cache?

hier mein PHP script:

PHP:
$photo_src = $_FILES['photo']['tmp_name'];

if (is_file($photo_src)) {
   
    $photo_dest = 'images/photo_'.time().'.jpg';

$size = getimagesize($photo_src);
$width       = $size[0];
$height      = $size[1];


$over_width  = $width / 700;
$over_height = $height / 400;



if($over_width > 1 OR $over_height > 1)
{
   if($over_width > $over_height)
  {
     $width = $width / $over_width;
     $height = $height / $over_width;
  }
  else{
    $width = $width / $over_height;
    $height = $height / $over_height;
  }
}
$src = imagecreatefromstring(file_get_contents($photo_src));
$dst = imagecreatetruecolor($width,$height);
imagecopyresampled($dst,$src,0,0,0,0,$width,$height,$size[0],$size[1]);
//imagedestroy($src);
imagejpeg($dst,$photo_dest); // adjust format as needed
//imagedestroy($dst);   
   
    echo '<script type="text/javascript">window.top.window.show_popup_crop("'.$photo_dest.'")</script>';
}
 
Ich bin sicherlich kein PHP-Experte, aber für mich klingt das nach einer "Cache" Sache. Wenn ein neues Bild verwendet werden soll, dann bitte auch alles neu laden und das alte Zeug "destroyen".
 
Das Bild wird bei mir schon in der Crop-Auswahlbox disproportioniert dargestellt. Deswegen vermute ich einen Fehler im JS. Kannst du den Code mal zeigen?
 
Hallo,

sry dass ich jetzt erst auf die sachen Antworte. hatte noch andere Baustellen zu erledigen und habe das hier komplett aus den Augen verloren. Zu ComFreak, hier ist der gewünschte Js Code:

Javascript:
var TARGET_W = 600;
var TARGET_H = 400;

// show loader while uploading photo
function submit_photo() {
    // display the loading texte
    $('#loading_progress').html('<img src="images/loader.gif"> Uploading your photo...');
}

// show_popup : show the popup
function show_popup(id) {
    // show the popup
    $('#'+id).show();
}

// close_popup : close the popup
function close_popup(id) {
    // hide the popup
    $('#'+id).hide();
}

// show_popup_crop : show the crop popup
function show_popup_crop(url) {
    // change the photo source
    $('#cropbox').attr('src', url);
    // destroy the Jcrop object to create a new one
    try {
        jcrop_api.destroy();
    } catch (e) {
        // object not defined
    }
    // Initialize the Jcrop using the TARGET_W and TARGET_H that initialized before
    $('#cropbox').Jcrop({
      aspectRatio: TARGET_W / TARGET_H,
      setSelect:   [ 100, 100, TARGET_W, TARGET_H ],
      onSelect: updateCoords
    },function(){
        jcrop_api = this;
    });

    // store the current uploaded photo url in a hidden input to use it later
    $('#photo_url').val(url);
    // hide and reset the upload popup
    $('#popup_upload').hide();
    $('#loading_progress').html('');
    $('#photo').val('');

    // show the crop popup
    $('#popup_crop').show();
}

// crop_photo :
function crop_photo() {
    var x_ = $('#x').val();
    var y_ = $('#y').val();
    var w_ = $('#w').val();
    var h_ = $('#h').val();
    var photo_url_ = $('#photo_url').val();

    // hide thecrop  popup
    $('#popup_crop').hide();

    // display the loading texte
    $('#photo_container').html('<img src="images/loader.gif"> Processing...');
    // crop photo with a php file using ajax call
    $.ajax({
        url: 'crop_photo.php',
        type: 'POST',
        data: {x:x_, y:y_, w:w_, h:h_, photo_url:photo_url_, targ_w:TARGET_W, targ_h:TARGET_H},
        success:function(data){
            // display the croped photo
            $('#photo_container').html(data);
        }
    });
}

// updateCoords : updates hidden input values after every crop selection
function updateCoords(c) {
    $('#x').val(c.x);
    $('#y').val(c.y);
    $('#w').val(c.w);
    $('#h').val(c.h);
}

hoffe du bekommst das mit und kannst mir da weiter helfen.

:)
 

Neue Beiträge

Zurück