There is a form through which people upload images to the site. The script checks if it is a picture or not, if it is a picture, it saves it and outputs it to the browser. How to make so that when loading through a form the picture is cropped to the size of 100 by 100 pixels? So far, Google hasn’t found anything in Google.

Here is the actual PHP code:

if(isset($_FILES['filename']['name'])) { $name = $_FILES['filename']['name']; $typeok = TRUE; #### #$name = strtolower(ereg_replace("[^A-Za-z0-9.]", "", $name); //Π‘ΠΊΡ€ΠΈΠΏΡ‚ пСрСстаСт Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ, Ссли Ρ€Π°ΡΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ эту строчку(( switch($_FILES['filename']['type']) { case 'image/jpeg': $ext = 'jpg'; break; case 'image/pjpeg': $ext = 'jpg'; break; case 'image/gif': $ext = 'gif'; break; case 'image/png': $ext = 'png'; break; case 'image/tiff': $ext = 'tif'; break; default: $typeok = FALSE; break; } if($ext) { $n = strtolower("$name"); move_uploaded_file($_FILES['filename']['tmp_name'], "images/users/$n"); echo("<div class=\"alert alert-success\">"); echo("<p>Π—Π°Π³Ρ€ΡƒΠΆΠ΅Π½ΠΎ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ $name ΠΏΠΎΠ΄ ΠΈΠΌΠ΅Π½Π΅ΠΌ $n: </p><br>"); echo("<img src='images/users/$n'>"); echo("</div>"); } else { echo("<div class=\"alert alert-error\">"); echo ("<p>'$name' - Π½Π΅ΠΏΡ€ΠΈΠ΅ΠΌΠ»ΠΈΠΌΡ‹ΠΉ Ρ„Π°ΠΉΠ» изобраТСния</p>"); echo("</div>"); } } else { echo("<div class=\"alert alert-error\">"); echo ("<p>Π—Π°Π³Ρ€ΡƒΠ·ΠΊΠΈ изобраТСния Π½Π΅ ΠΏΡ€ΠΎΠΈΠ·ΠΎΡˆΠ»ΠΎ!</p>"); echo("</div>"); } 
  • one
    $ name = strtolower (ereg_replace ("[^ A-Za-z0-9.]", "", $ name); ---------- $ name = strtolower (ereg_replace ("[^ A- Za-z0-9.] "," ", $ Name)); - activist
  • one
    The procedure is based on the example of JPEG: imagecreatetruecolor, imagecreatefromjpeg, imagecopyresampled, imagejpeg Create an empty image with dimensions 100x100, load an existing image, copy the necessary part of the image into an empty one, save it. - activist
  • Thanks for the tips, now try to implement! - spoilt

2 answers 2

Here is an interesting plugin: cropping pictures

    You can like this:

     $crop_x = ...; $crop_y = ...; $crop_width = ...; $crop_height = ...; $image_p = imagecreatetruecolor($crop_width, $crop_height); $image = imagecreatefromjpeg(...); imagecopyresampled($image_p, $image, 0, 0, $crop_x, $crop_y, $crop_width, $crop_height, $crop_width, $crop_height); $img_data = tempnam("/tmp","crop"); //сохраняСм Ρ‚ΡƒΡ‚ ΠΏΠΎ ΠΈΠΌΠ΅Π½ΠΈ $img_data imagejpeg($image_p, $img_data); imagedestroy($image_p); imagedestroy($image); unlink($img_data);