-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
490 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ts/2024/2024-12-19-Add_margin_to_epub_manga_images_for_the_ebook_Sony_PRS-T2.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
title: "Add margin to epub manga images for the ebook Sony PRS-T2" | ||
date: "2024-12-19 10:54" | ||
--- | ||
|
||
I have an old Sony PRS-T2 which works perfectly. I wanted to put some manga on it but there is this bar on the bottom with the page number that is hidding part of the images ([sometimes also text](https://www.reddit.com/r/Calibre/comments/nyfyap/sony_prst2_space_in_top_missing_text_on_bottom/), so I am not the only one with this problem). | ||
|
||
 | ||
|
||
I think there is other possibilities like css but I did not succeed really and testing was pain. | ||
|
||
My files are .cbz in really good quality. I used [KCC (a.k.a. Kindle Comic Converter)](https://github.com/ciromattia/kcc) to convert them in epub, crop them to a specific resolution to get the maximum of it ... here the parameters I used: | ||
|
||
 | ||
|
||
What I did then was just add some pixel at the bottom of the pictures. I used bash via WSL. | ||
|
||
*Steps:* | ||
|
||
- rename the epub to zip | ||
- unzip it | ||
- add the 100 white pixel to the bottom of each pictures | ||
- rezip in epub | ||
|
||
Here the source code: | ||
|
||
```sh | ||
#!/bin/bash -i | ||
|
||
wd=$(pwd) | ||
mkdir converted | ||
|
||
for j in *epub; do | ||
|
||
# get the names from the loop needed | ||
filenameepub=$j | ||
filename=$(basename "$filenameepub" .epub) | ||
cp "$filenameepub" "${filename}.zip" # rename the epub to zip | ||
unzip "${filename}.zip" -d "${filename}" # unzip it | ||
cd "${filename}/OEBPS/Images" # go to the wanted directory where the pictures are | ||
|
||
for i in *jpg; do | ||
nname=$(basename "$i" .jpg)_temp.jpg | ||
mv "$i" "$nname" # rename the original picture | ||
convert "$nname" -background white -gravity south -splice 0x70 "$i" # use imagemagick to add 70px to the bottom | ||
rm "$nname" # remove the temp picture | ||
done | ||
|
||
cd "${wd}/${filename}" | ||
zip -r "../converted/${filename}_new.epub" "./" # rezip the epub | ||
cd "$wd" | ||
rm "${filename}.zip" # remove the temp files left | ||
rm -r "$filename" | ||
|
||
done | ||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
title: "Html table with images to xlsx with python" | ||
date: "2024-12-24 14:53" | ||
--- | ||
|
||
How to convert a html table with images to xlsx with those images included. | ||
Here you have to adapt your code with input output (here info.html and info.xlsx). | ||
|
||
```python | ||
import os | ||
import requests | ||
import pandas as pd | ||
from bs4 import BeautifulSoup | ||
from openpyxl import Workbook | ||
from openpyxl.drawing.image import Image | ||
from io import StringIO | ||
|
||
|
||
# Function to convert column index to Excel column letter(s) | ||
def col_idx_to_excel(col_idx): | ||
result = '' | ||
while col_idx >= 0: | ||
result = chr(col_idx % 26 + 65) + result | ||
col_idx = col_idx // 26 - 1 | ||
return result | ||
|
||
|
||
# Read the HTML file and parse it with BeautifulSoup | ||
html_file = 'info.html' # Replace with your HTML file | ||
with open(html_file, 'r') as file: | ||
html_content = file.read() | ||
|
||
# Parse the HTML with BeautifulSoup | ||
soup = BeautifulSoup(html_content, 'html.parser') | ||
table = soup.find('table') # Assuming there's only one table in the HTML | ||
|
||
# Find all <img> tags and extract the URLs | ||
img_tags = soup.find_all('img') | ||
# Extract image sources (src attributes) and their positions | ||
img_sources = {} | ||
for row_idx, tr in enumerate(table.find_all('tr')): | ||
for col_idx, td in enumerate(tr.find_all('td')): | ||
img = td.find('img') | ||
if img: | ||
# Store the image source in a dictionary with (row_idx, col_idx) as the key | ||
img_sources[(row_idx, col_idx)] = img['src'] | ||
|
||
# Create a new workbook | ||
wb = Workbook() | ||
ws = wb.active | ||
|
||
# Read the HTML table and convert it to DataFrame | ||
df = pd.read_html(StringIO(str(table)))[0] | ||
|
||
|
||
# Write the table data to the Excel sheet | ||
for row_idx, row in df.iterrows(): | ||
for col_idx, cell in enumerate(row): | ||
ws.cell(row=row_idx + 1, column=col_idx + 1, value=cell) | ||
|
||
# Replace the corresponding cells in the DataFrame with image sources | ||
for (row_idx, col_idx), img_src in img_sources.items(): | ||
# Convert the column index to Excel-style letter(s) | ||
col_letter = col_idx_to_excel(col_idx) | ||
# Add the image to the corresponding cell in Excel | ||
img = Image(img_src) | ||
img.anchor = f'{col_letter}{row_idx}' # Adjust the cell where the image will be inserted | ||
ws.add_image(img) | ||
|
||
# Save the workbook | ||
excel_file = 'info.xlsx' | ||
wb.save(excel_file) | ||
|
||
print(f"HTML table with images has been successfully converted to {excel_file}") | ||
|
||
``` | ||
|
||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.