PHPackages                             perchten/wordpress\_attachmentfromimg - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. perchten/wordpress\_attachmentfromimg

ActiveLibrary[Image &amp; Media](/categories/media)

perchten/wordpress\_attachmentfromimg
=====================================

Single function to get wordpress attachment id from an img src

1.0.4(11y ago)026MITPHPPHP &gt;=5.3.0

Since May 27Pushed 11y ago1 watchersCompare

[ Source](https://github.com/perchten/wordpressAttachmentFromImg)[ Packagist](https://packagist.org/packages/perchten/wordpress_attachmentfromimg)[ Docs](https://github.com/perchten/wordpressAttachmentFromImg)[ RSS](/packages/perchten-wordpress-attachmentfromimg/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (4)Used By (0)

wordpressAttachmentIdFromImg
============================

[](#wordpressattachmentidfromimg)

Single function to get wordpress attachment id from an img src, regardless of whether the img src is a resized thumbnail or the original image.

Usage
-----

[](#usage)

### Installation

[](#installation)

##### Via Composer

[](#via-composer)

Neat\_html is available on Packagist ([perchten/wordpress\_attachmentfromimg](https://packagist.org/packages/perchten/wordpress_attachmentfromimg)) and as such is installable via [Composer](https://getcomposer.org/).

Add the following to your `composer.json`

```
{
	"require": {s
    	"perchten/wordpress_attachmentfromimg": "1.*"
    }
}

```

##### Direct include

[](#direct-include)

Clone or download from [GitHub](https://github.com/perchten/wordpressAttachmentFromImg) and include directly in your code:

```
require_once "path/to/neat_html.php"

```

### Code

[](#code)

Basic usage to get the ID:

```
get_attachment_id_from_img_src($image_src)

```

If you want a specific thumbnail img src rather than just the ID, you can also use:

```
get_attachment_id_from_img_src($image_src,$thumb)

```

This will only work if the thumbnail size has been previously defined. It will NOT return the `` tag, but just the src url. It will also not return the image metadata such as size. If you need that, then use the inbuilt Wordpress function [`wp_get_attachment_image_src()`](http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src) instead.

Why Not A Wordpress Plugin?
---------------------------

[](#why-not-a-wordpress-plugin)

Because it's tiny and only useful for developers.

If you're a developer and unfamiliar with Composer, go [check it out](https://getcomposer.org/). You can use it to load utility libraries into your plugins or themes.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

4370d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b8f0c1a2465186a4ff26665a3b9062d5512e53cda847446e1f6040c624112fe?d=identicon)[perchten](/maintainers/perchten)

---

Top Contributors

[![builtbybrayne](https://avatars.githubusercontent.com/u/2118872?v=4)](https://github.com/builtbybrayne "builtbybrayne (6 commits)")

---

Tags

wordpressimageutilfunctionalattachment

### Embed Badge

![Health badge](/badges/perchten-wordpress-attachmentfromimg/health.svg)

```
[![Health](https://phpackages.com/badges/perchten-wordpress-attachmentfromimg/health.svg)](https://phpackages.com/packages/perchten-wordpress-attachmentfromimg)
```

###  Alternatives

[stefangabos/zebra_image

A single-file, lightweight PHP library designed for efficient image manipulation featuring methods for modifying images and applying filters

141110.4k6](/packages/stefangabos-zebra-image)[toinekamps/responsive-pics

Responsive Pics is a Wordpress tool for resizing images on the fly.

831.2k](/packages/toinekamps-responsive-pics)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
