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