I do the resize function of the image for the parser from YouTube, the original images are too large in maxresdefault but the quality ones. How can I do if the image is less than 700px then we can’t resize it? here is the function itself

# Ѐункция для Π·Π°Π³Ρ€ΡƒΠ·ΠΊΠΈ ΠΈ рСсайза ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ function youtube_thumb($thumb, $youtube_thumb, $preview_path, $original_path, $size ) { /* * $thumb - Π½ΠΎΠ²ΠΎΠ΅ имя Π½Π° ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ * $youtube_thumb - ссылка Π½Π° ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ * $preview_path - ΠΏΠ°ΠΏΠΊΠ°, ΠΊΡƒΠ΄Π° сохраняСм ΠΏΡ€Π΅Π²ΡŒΡŽΡˆΠΊΠΈ * $original_path - ΠΏΠ°ΠΏΠΊΠ°, ΠΊΡƒΠ΄Π° сохраняСм ΠΎΡ€ΠΈΠ³ΠΈΠ½Π°Π» * $size - Ρ€Π°Π·ΠΌΠ΅Ρ€ большСй стороны (Π² пиксСлях) */ # ΠŸΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅. Если функция Π½Π΅ ΠΎΡ‚Ρ€Π°Π±ΠΎΡ‚Π°Π»Π° if( $image = file_get_contents( $youtube_thumb ) ) { # БохраняСм ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ file_put_contents( $thumb, $image ); # ΠžΡ‡ΠΈΡ‰Π°Π΅ΠΌ ΠΏΠ°ΠΌΡΡ‚ΡŒ unset( $image ); # Если getimagesize Π²Π΅Ρ€Π½ΡƒΠ»Π° массив if( $info = getimagesize( $thumb ) ) { # ВычисляСм Ρ‚ΠΈΠΏ изобраТСния $type = trim( strrchr( $info['mime'], '/' ), '/' ); # Π˜ΡΡ…ΠΎΠ΄Ρ ΠΈΠ· Ρ‚ΠΈΠΏΠ° Ρ„ΠΎΡ€ΠΌΠΈΡ€ΡƒΠ΅ΠΌ названия Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΉ $imagecreate = 'imagecreatefrom' . $type; $imagesave = 'image' . $type; $imagename = $thumb; # ΠŸΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ Π΄Π°Π½Π½Ρ‹Π΅ ΠΎΠ± ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΈ list( $width, $height ) = $info; # Π‘ΠΎΠ·Π΄Π°Ρ‘ΠΌ рСсурс изобраТСния $src_im = $imagecreate( $thumb ); # ВычисляСм ΡˆΠΈΡ€ΠΈΠ½Ρƒ $new_width = $width > $height ? $size : ceil( ( $width * $size ) / $height ); # ВычисляСм высоту $new_height = $width < $height ? $size : ceil( ( $height * $size ) / $width ); # Π‘ΠΎΠ·Π΄Π°Ρ‘ΠΌ Π½ΠΎΠ²ΠΎΠ΅ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ $dst_im = imagecreatetruecolor( $new_width, $new_height ); # РСсайзим imagecopyresampled( $dst_im, $src_im, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); # Чистим ΠΏΠ°ΠΌΡΡ‚ΡŒ unset( $src_im ); # БохраняСм ΠΎΡ€ΠΈΠ³ΠΈΠ½Π°Π» if( !copy( $youtube_thumb, $original_path . $imagename ) ) $return = false; # БохраняСм ΠΏΡ€Π΅Π²ΡŒΡŽΡˆΠΊΡƒ if( !$imagesave( $dst_im, $preview_path . $imagename ) ) $return = false; # ΠžΡ‡ΠΈΡ‰Π°Π΅ΠΌ ΠΏΠ°ΠΌΡΡ‚ΡŒ unset( $dst_im ); unlink( $thumb ); } } } 
  • if($width<700){ # РСсайзим imagecopyresampled( $dst_im, $src_im, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); } if($width<700){ # РСсайзим imagecopyresampled( $dst_im, $src_im, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); } ??? - DaemonHK
  • so creates an empty black drawing - Petro Boyko

1 answer 1

It seems like this `

  #Ссли ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ мСньшС $size Ρ‚ΠΎ Π½Π΅ рСсайзим if($width <= $size) {$new_width = $width; $new_height = $height;} # Π‘ΠΎΠ·Π΄Π°Ρ‘ΠΌ Π½ΠΎΠ²ΠΎΠ΅ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅`