
Research
Namastex.ai npm Packages Hit with TeamPCP-Style CanisterWorm Malware
Malicious Namastex.ai npm packages appear to replicate TeamPCP-style Canister Worm tradecraft, including exfiltration and self-propagation.
funimage
Advanced tools
一个强大的 Python 图像格式转换和处理库。FunImage 提供了 PIL 图像、OpenCV 数组、字节、base64、URL 和文件路径之间的无缝转换功能。
A powerful Python library for image format conversion and processing. FunImage provides seamless conversion between various image formats including PIL Images, OpenCV arrays, bytes, base64, URLs, and file paths.
pip install funimage
安装 OpenCV 支持 For OpenCV support:
pip install funimage[opencv]
开发环境 For development:
pip install funimage[dev]
import funimage
# Convert URL to PIL Image
pil_img = funimage.convert_to_pilimg("https://example.com/image.jpg")
# Convert PIL Image to bytes
img_bytes = funimage.convert_to_bytes(pil_img)
# Convert to base64 string
base64_str = funimage.convert_to_base64_str(img_bytes)
# Save to file
funimage.convert_to_file("https://example.com/image.jpg", "output.jpg")
| Type | Description | Example |
|---|---|---|
| URL | HTTP/HTTPS image URLs | "https://example.com/image.jpg" |
| File Path | Local file paths | "/path/to/image.jpg" |
| PIL Image | PIL Image objects | PIL.Image.open("image.jpg") |
| Bytes | Raw image bytes | open("image.jpg", "rb").read() |
| Base64 | Base64 encoded strings | "data:image/jpeg;base64,..." |
| NumPy Array | OpenCV/NumPy arrays | cv2.imread("image.jpg") |
| BytesIO | BytesIO objects | BytesIO(image_bytes) |
convert_to_pilimg(image, image_type=None)Convert any supported image format to PIL Image.
# From URL
pil_img = funimage.convert_to_pilimg("https://example.com/image.jpg")
# From file
pil_img = funimage.convert_to_pilimg("/path/to/image.jpg")
# From bytes
pil_img = funimage.convert_to_pilimg(image_bytes)
convert_to_bytes(image, image_type=None)Convert any supported image format to bytes.
# From PIL Image
img_bytes = funimage.convert_to_bytes(pil_image)
# From URL
img_bytes = funimage.convert_to_bytes("https://example.com/image.jpg")
convert_to_cvimg(image, image_type=None)Convert any supported image format to OpenCV numpy array.
# From PIL Image
cv_img = funimage.convert_to_cvimg(pil_image)
# From URL
cv_img = funimage.convert_to_cvimg("https://example.com/image.jpg")
convert_to_base64_str(image, image_type=None)Convert any supported image format to base64 string.
# From PIL Image
b64_str = funimage.convert_to_base64_str(pil_image)
# From file
b64_str = funimage.convert_to_base64_str("/path/to/image.jpg")
convert_to_file(image, output_path, image_type=None)Save any supported image format to file.
# From URL to file
funimage.convert_to_file("https://example.com/image.jpg", "local_copy.jpg")
# From PIL Image to file
funimage.convert_to_file(pil_image, "output.png")
parse_image_type(image, image_type=None)Detect the type of input image.
from funimage import ImageType, parse_image_type
img_type = parse_image_type("https://example.com/image.jpg")
print(img_type) # ImageType.URL
from funimage import ImageType
ImageType.URL # HTTP/HTTPS URLs
ImageType.FILE # Local file paths
ImageType.PIL # PIL Image objects
ImageType.BYTES # Raw bytes
ImageType.BASE64_STR # Base64 strings
ImageType.NDARRAY # NumPy arrays
ImageType.BYTESIO # BytesIO objects
from funimage import ImageType
# Explicitly specify input type
pil_img = funimage.convert_to_pilimg(
image_data,
image_type=ImageType.BYTES
)
try:
pil_img = funimage.convert_to_pilimg("https://invalid-url.com/image.jpg")
except Exception as e:
print(f"Conversion failed: {e}")
urls = [
"https://example.com/image1.jpg",
"https://example.com/image2.jpg",
"https://example.com/image3.jpg"
]
for i, url in enumerate(urls):
funimage.convert_to_file(url, f"image_{i}.jpg")
import requests
from bs4 import BeautifulSoup
import funimage
# Scrape images from a webpage
response = requests.get("https://example.com")
soup = BeautifulSoup(response.content, 'html.parser')
for i, img in enumerate(soup.find_all('img')):
img_url = img.get('src')
if img_url:
try:
funimage.convert_to_file(img_url, f"scraped_image_{i}.jpg")
print(f"Saved image {i}")
except Exception as e:
print(f"Failed to save image {i}: {e}")
import funimage
# Convert PNG to JPEG
png_image = funimage.convert_to_pilimg("input.png")
funimage.convert_to_file(png_image, "output.jpg")
# Convert to WebP
funimage.convert_to_file("input.jpg", "output.webp")
import funimage
import requests
def upload_image_to_api(image_path):
# Convert image to base64 for API
b64_str = funimage.convert_to_base64_str(image_path)
payload = {
"image": b64_str,
"format": "jpeg"
}
response = requests.post("https://api.example.com/upload", json=payload)
return response.json()
欢迎贡献!请随时提交 Pull Request。Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)本项目基于 MIT 许可证 - 详情请查看 LICENSE 文件。This project is licensed under the MIT License - see the LICENSE file for details.
如果您遇到任何问题或有疑问,请在 GitHub 上 提交 issue。If you encounter any issues or have questions, please open an issue on GitHub.
FAQs
A powerful Python library for image format conversion and processing
We found that funimage demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
Malicious Namastex.ai npm packages appear to replicate TeamPCP-style Canister Worm tradecraft, including exfiltration and self-propagation.

Product
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.