Need help? Check out our Support site, then


image upload

  1. please help me,

    The following code used for ratio based image resizing.But it provide 1 part of the image from moriginal image.I need to resize the image with quality.

    <form name="myForm" action="uploadpic.php" method="post" enctype="multipart/form-data" />
    <input name="userfile" type="file" size="40" />
    <?

    if (@is_uploaded_file($_FILES["userfile"]["tmp_name"]))
    {

    $img_name = uploadPic("player","userfile","picupload/",150,150,1,"destination_name.jpg");

    //echo $img_name;

    }
    function uploadPic($prefix,$formSrc,$dDir,$maxWidth,$maxHeight,$resizeFlag,$tempName)
    {

    if (!copy($_FILES[$formSrc]["tmp_name"],$dDir.$_FILES[$formSrc]["name"]))
    {

    echo "failed to copy $file...\n";

    }

    if ($tempName == "") { $tempName = $prefix."_".mt_rand().".jpg"; }

    //hard copy of picture
    $src_img = $dDir.$_FILES[$formSrc]["name"];

    //destination
    $dest = $dDir.$tempName;

    //get source dimentions
    $src_dims = getImageSize($src_img);

    //create appropriate temp image
    switch ($src_dims[2]) {
    case 1: //GIF
    break;

    case 2: //JPEG
    $srcImage = imageCreateFromJpeg($src_img);
    break;

    case 3: //PNG
    break;

    default:
    return false;
    break;
    }

    $srcRatio = $src_dims[0]/$src_dims[1]; // width/height ratio
    $destRatio = $maxWidth/$maxHeight;

    echo $srcRatio."<br>";
    echo $destRatio;

    if ($destRatio > $srcRatio) {
    $destSize[1] = $maxHeight;
    $destSize[0] = $maxHeight*$srcRatio;
    }
    else {
    $destSize[0] = $maxWidth;

    $destSize[1] = $maxWidth/$srcRatio;

    }

    //if set image dimensions are required:
    if ($resizeFlag == 1) {
    $destSize[0] = $maxWidth;
    $destSize[1] = $maxHeight;

    }

    $thumb_w = $destSize[0];
    $thumb_h = $destSize[1];

    $dst_img = imageCreateTrueColor($thumb_w,$thumb_h);

    imageCopyResampled($dst_img,$srcImage,0,0,0,0,$thumb_w,$thumb_h,$maxWidth,$maxHeight);

    switch ($src_dims[2])
    {
    case 1:
    break;
    case 2:
    imageJpeg($dst_img, $dest, 75); //75 denotes image quality / compression ratio
    break;

    case 3:
    break;
    }
    //$y++;

    unlink($src_img);
    return $tempName;
    }
    ?>
    <input type="submit" name="submit" value="submit">
    </form>

    <img src="picupload/destination_name.jpg">

  2. If you are able to do this you are not on blogging on a WordPress.com blog - you must have your own instance of wordpress. We use wordpress MU software here so we are unable to help. Go to the forums at http://wordpress.org/support - they should be able to.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.