Python Forum
New2Python: Help with Importing/Mapping Image Src to Image Code in File
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New2Python: Help with Importing/Mapping Image Src to Image Code in File
#1
I am creating an item catalogue of our products and need to import the item images besides their product codes'. The Image Code in the file is the same as the image saved name.

I've automated a SQL query for the table and connected it to Python, exporting it into an Excel file.

## SQL Query
sql_query = pd.read_sql_query('''

SELECT TOP 250 '' AS 'Image', LEFT(stockcode, 4)+RIGHT(stockcode, 4) AS 'Image Code', [stockcode], [Description]
FROM V_Sale_TurnOver sto
WHERE [PostingDate] BETWEEN '2022-01-01' AND getdate()
GROUP BY [Range], [stockcode], [Description]

    ''' ,conn) 

df = pd.DataFrame(sql_query)

## Export to Folder
df.to_csv (r'G:\Outbound\Reports\Top 250 SKU/Top250SKU.csv', index = False)
I need to map the product images to their image codes' (i.e., if a product Image Code = 'AURO0002', I need to import and map it to the saved image file 'AURO0002').

Also, if the Image Code does not map to anything, I need the code to prevent errors from occurring. If it helps, below is a similar script written on VBA Script for a similar task.

# VBA Code
rowNo = 1

dim ImgPath As String, NoImagePath As String
NoImagePath = "\\g_drive\Images\NoImage.jpg"
While Top250SKU.cells(rowNo, 2).Value <>
    If Rs2.RecordCount <> 0 Then Rs2.MoveFirst
    Do While Not Rs2.EOF

        If ActiveSheet.Cells(rowNo, 2).Value = Rs2!stockcode And _
                ActiveSheet.Cells(rowNo, 3).Value = Rs2!Description Then

       End If
        Rs2.MoveNext
    Loop
    ActiveSheet.Cells(4, 1).Value = "Image"

   ImgPath = "\\g_drive\Images\" & ActiveSheet.Cells(rowNo, 2).Value & ".jpg"
    If FileExists(ImgPath) = False Then
        ImgPath = NoImagePath
    End If
    Rows(rowNo & ":" & rowNo).RowHeight = 60
    Call InsertPictureIG(ImgPath, ActiveSheet.Cells(rowNo, 1).Address)
rowNo = rowNo + 1
How can I go about coding this?
Larz60+ write Nov-17-2022, 08:50 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.

Attached Files

Thumbnail(s)
   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo image error pyc0de 2 290 Mar-23-2024, 06:20 PM
Last Post: pyc0de
  Using OpenCV and image path is invalid AudunNilsen 5 579 Mar-18-2024, 05:28 PM
Last Post: snippsat
  Count image's colors very fast flash77 18 1,591 Mar-05-2024, 06:12 PM
Last Post: deanhystad
  Convert numpy array to image without loading it into RAM. DreamingInsanity 7 5,916 Feb-08-2024, 09:38 AM
Last Post: paul18fr
  error "cannot identify image file" part way through running hatflyer 0 683 Nov-02-2023, 11:45 PM
Last Post: hatflyer
  Mirror Video Image in realtime makingwithheld 1 443 Oct-30-2023, 02:45 PM
Last Post: Larz60+
  howto get size of a ctk image? janeik 2 886 Oct-03-2023, 03:49 AM
Last Post: janeik
  Use of PIL.Image nafshar 12 2,146 Sep-07-2023, 11:02 PM
Last Post: nafshar
Question image manipulation (cropping and MetaData) SpongeB0B 4 1,170 Jul-03-2023, 06:35 PM
Last Post: SpongeB0B
  Save image from outlook email cubangt 1 711 Jun-07-2023, 06:52 PM
Last Post: cubangt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020