Is there a function to create thumbnails image in wordpress in the URL?

Hello, I'm developing a plugin for Wordpress and my database has the path to the required images. They need to display in the front in the thumbnails. In the documentation I found a wonderful feature:
<?= wp_get_attachment_image( $attachment_id, $size, $icon ); ?>
But the fact that I will not be able to get the $attachment_id in the output image. Is there an analogue of such a function, only where the argument can indicate the path to the picture?
July 2nd 19 at 14:24
1 answer
July 2nd 19 at 14:26

// retrieves the attachment ID from the file URL
pippin_get_image_id function($image_url) {
 global $wpdb;
 $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url )); 
 return $attachment[0]; 

// set the image url
$image_url = '';

// store the image ID in a var
$image_id = pippin_get_image_id($image_url);

// retrieve the thumbnail size of our image
$image_thumb = wp_get_attachment_image_src($image_id, 'thumbnail');

// display the image
echo $image_thumb[0];

If I understand correctly the idea of the author, he pictures in the media library is not going to keep, hence the inability to get the attachment_id. - Velva.Rogahn commented on July 2nd 19 at 14:29
: re-read it a couple of times. Yeah, maybe. But then, I think, is easier to use some library to work with images. - alexandrea_Vandervo commented on July 2nd 19 at 14:32
: Exactly. Although it is generally a bad idea. However, it's better to clarify that we guess will - Velva.Rogahn commented on July 2nd 19 at 14:35
: No, I'll just store images in the wordpress media Manager, but it originally came out, but I didn't think and in the database began to write down the url and not the image url. So the answer is the solution - victor_Rolfson commented on July 2nd 19 at 14:38
: thank you, just what I was looking for - victor_Rolfson commented on July 2nd 19 at 14:41
: so change before its too late. It is better to work the right way immediately, even if you need to refactor a bit of code. - Velva.Rogahn commented on July 2nd 19 at 14:44

Find more questions by tags WordPress